From patchwork Sun Mar 28 18:33:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: piastry@etersoft.ru X-Patchwork-Id: 48786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.samba.org (fn.samba.org [216.83.154.106]) by ozlabs.org (Postfix) with ESMTP id 8ACFEB7C06 for ; Mon, 29 Mar 2010 05:33:45 +1100 (EST) Received: from fn.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id F2913465A8; Sun, 28 Mar 2010 12:33:45 -0600 (MDT) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fn.samba.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.8 tests=AWL, BAYES_00 autolearn=ham version=3.2.5 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from mail.etersoft.ru (mail.etersoft.ru [87.249.47.46]) by lists.samba.org (Postfix) with ESMTP id 027AEAD0D8 for ; Sun, 28 Mar 2010 12:33:39 -0600 (MDT) From: piastry@etersoft.ru To: Jeff Layton Date: Sun, 28 Mar 2010 22:33:35 +0400 User-Agent: KMail/1.13.1 (Linux/2.6.32.9-70.fc12.x86_64; KDE/4.4.1; x86_64; ; ) References: <201003241155.32348.piastry@etersoft.ru> <20100326215728.2409b25f@tlielax.poochiereds.net> In-Reply-To: <20100326215728.2409b25f@tlielax.poochiereds.net> MIME-Version: 1.0 Message-Id: <201003282233.36549.piastry@etersoft.ru> Cc: linux-cifs-client@lists.samba.org Subject: Re: [linux-cifs-client] [PATCH 1/3] #6823 page reading with mandatory locking style X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-cifs-client-bounces@lists.samba.org Errors-To: linux-cifs-client-bounces@lists.samba.org В сообщении от 27 марта 2010 04:57:28 вы написали: > On Wed, 24 Mar 2010 11:55:31 +0300 > > piastry@etersoft.ru wrote: > > diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c > > index 5183bc2..2b894bd 100644 > > --- a/fs/cifs/cifsfs.c > > +++ b/fs/cifs/cifsfs.c > > @@ -616,6 +616,51 @@ cifs_get_sb(struct file_system_type *fs_type, > > > > return 0; > > > > } > > > > +static ssize_t cifs_sync_read(struct file *filp, char __user *buf, > > + size_t len, loff_t *ppos) > > +{ > > + int retval, read, posix_locking = 0; > > + struct file_lock pfLock; > > + struct cifsInodeInfo *cifsInode; > > + struct cifs_sb_info *cifs_sb; > > + struct cifsTconInfo *tcon; > > + > > + cifs_sb = CIFS_SB(filp->f_path.dentry->d_sb); > > + tcon = cifs_sb->tcon; > > + if ((tcon->ses->capabilities & CAP_UNIX) && > > + (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && > > + ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) > > + posix_locking = 1; > > + > > + retval = cifs_revalidate(filp->f_path.dentry); > > + if (retval < 0) > > + return (ssize_t)retval; > > + > > + memset(&pfLock, 0, sizeof(pfLock)); > > + pfLock.fl_type = F_RDLCK; > > + pfLock.fl_start = *ppos; > > + pfLock.fl_end = *ppos+len; > > + cifsInode = CIFS_I(filp->f_path.dentry->d_inode); > > + if (cifsInode == NULL) > > + return -ENOENT; > > + > > + if (!CIFS_I(filp->f_path.dentry->d_inode)->clientCanCacheRead && > > + !posix_locking) { > > + retval = cifs_lock(filp, F_GETLK, &pfLock); > > + if (retval < 0) > > + return (ssize_t)retval; > > + if (pfLock.fl_type == F_UNLCK) > > + read = do_sync_read(filp, buf, len, ppos); > > + else > > + return -EACCES; > > + } else > > + read = do_sync_read(filp, buf, len, ppos); > > + > > + if (read == -EACCES && !posix_locking) > > + read = cifs_user_read(filp, buf, len, ppos); > > + return read; > > +} > > + > > > > static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct > > iovec *iov, > > > > unsigned long nr_segs, loff_t pos) > > > > { > > > > @@ -737,7 +782,7 @@ const struct inode_operations cifs_symlink_inode_ops > > = { > > > > }; > > > > const struct file_operations cifs_file_ops = { > > > > - .read = do_sync_read, > > + .read = cifs_sync_read, > > > > .write = do_sync_write, > > .aio_read = generic_file_aio_read, > > .aio_write = cifs_file_aio_write, > > > > Signed-off-by: Pavel Shilovsky > > I have no clue what this patch is intended to do. Can you possibly > explain it, preferably in a resent patch with proper patch descripion > and signed-off-by line at the beginning? [CIFS] Fix page reading error with mandatory locking style If we lock file from one process from 1 to 2 and then try to read it from another from 0 to 1 without direct mount options, reading fails. That's why vfs tries to read whole page and fails due the lock from the first process. Signed-off-by: Pavel Shilovsky See patch in attachment. --- Best regards, Pavel Shilovsky. From 2e74c7d08b8f6e07a9ed0d76a4d6771eb0e63a4e Mon Sep 17 00:00:00 2001 From: Pavel Shilovsky Date: Sun, 28 Mar 2010 22:12:59 +0400 Subject: [PATCH] [CIFS] Fix page reading error with mandatory locking style If we lock file from one process from 1 to 2 and then try to read it from another from 0 to 1 without direct mount options, reading fails. That's why vfs tries to read whole page and fails due the lock from the first process. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsfs.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 46 insertions(+), 1 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index ded66be..79c6d0c 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -616,6 +616,51 @@ cifs_get_sb(struct file_system_type *fs_type, return 0; } +static ssize_t cifs_sync_read(struct file *filp, char __user *buf, + size_t len, loff_t *ppos) +{ + int retval, read, posix_locking = 0; + struct file_lock pfLock; + struct cifsInodeInfo *cifsInode; + struct cifs_sb_info *cifs_sb; + struct cifsTconInfo *tcon; + + cifs_sb = CIFS_SB(filp->f_path.dentry->d_sb); + tcon = cifs_sb->tcon; + if ((tcon->ses->capabilities & CAP_UNIX) && + (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && + ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) + posix_locking = 1; + + retval = cifs_revalidate(filp->f_path.dentry); + if (retval < 0) + return (ssize_t)retval; + + memset(&pfLock, 0, sizeof(pfLock)); + pfLock.fl_type = F_RDLCK; + pfLock.fl_start = *ppos; + pfLock.fl_end = *ppos+len; + cifsInode = CIFS_I(filp->f_path.dentry->d_inode); + if (cifsInode == NULL) + return -ENOENT; + + if (!CIFS_I(filp->f_path.dentry->d_inode)->clientCanCacheRead && + !posix_locking) { + retval = cifs_lock(filp, F_GETLK, &pfLock); + if (retval < 0) + return (ssize_t)retval; + if (pfLock.fl_type == F_UNLCK) + read = do_sync_read(filp, buf, len, ppos); + else + return -EACCES; + } else + read = do_sync_read(filp, buf, len, ppos); + + if (read == -EACCES && !posix_locking) + read = cifs_user_read(filp, buf, len, ppos); + return read; +} + static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, loff_t pos) { @@ -737,7 +782,7 @@ const struct inode_operations cifs_symlink_inode_ops = { }; const struct file_operations cifs_file_ops = { - .read = do_sync_read, + .read = cifs_sync_read, .write = do_sync_write, .aio_read = generic_file_aio_read, .aio_write = cifs_file_aio_write, -- 1.6.6.1