From patchwork Tue Nov 30 07:54:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 366181 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAU7tl8J026718 for ; Tue, 30 Nov 2010 07:55:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754166Ab0K3Hzr (ORCPT ); Tue, 30 Nov 2010 02:55:47 -0500 Received: from mail-ew0-f46.google.com ([209.85.215.46]:64081 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754117Ab0K3Hzq (ORCPT ); Tue, 30 Nov 2010 02:55:46 -0500 Received: by ewy5 with SMTP id 5so2546816ewy.19 for ; Mon, 29 Nov 2010 23:55:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:x-mailer; bh=v1EsBfG/f8gH6AX1Qm81igMPPhX+G1flan0Ina2sHS0=; b=hm4hqgjmz/aflbDBWt42m4Z6efHqhhhkJziFk6LtbTqKlGf3T3G0O8hFulWRjFcaSZ 2yYOyCkyMyTU8cgvNggEgHXQ/Am16Gn/34W7fDxY5LxmZo9NDWOKmMA/OlU0DUMAg4Ti xPfuucI1Xs+WEBnMAm9OD8fIsYmxjf1qt7lzk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer; b=akuWeDrCuzkavPlYV7ILzawIewl4S7yg6z+MtwYUnkYR51lx7P7Mt9Pp2t3W1i+RRC MW5kZ8RRVuA7jnhJGtfu++IlpPl563c2Gt/sRALGxxZC6aIx7AfIToA+yWJDiUGQvO/O d6xFCTaAWkdE1Y5EBRFogJJ56bIxhewtZkasg= Received: by 10.213.114.78 with SMTP id d14mr655774ebq.93.1291103745638; Mon, 29 Nov 2010 23:55:45 -0800 (PST) Received: from localhost.localdomain (pppoe-88-147-197-53.san.ru [88.147.197.53]) by mx.google.com with ESMTPS id x54sm6089087eeh.23.2010.11.29.23.55.44 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 29 Nov 2010 23:55:44 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 2/6] CIFS: Make read call work with strict cache mode (try #4) Date: Tue, 30 Nov 2010 10:54:30 +0300 Message-Id: <1291103671-2983-1-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.3.2 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 30 Nov 2010 07:55:49 +0000 (UTC) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 9c37897..370acdc 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -568,6 +568,46 @@ cifs_do_mount(struct file_system_type *fs_type, return dget(sb->s_root); } +static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, + unsigned long nr_segs, loff_t pos) +{ + struct inode *inode; + struct cifs_sb_info *cifs_sb; + ssize_t read = 0, retval; + unsigned long i; + + inode = iocb->ki_filp->f_path.dentry->d_inode; + cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb); + + if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 || + CIFS_I(inode)->clientCanCacheRead) + return generic_file_aio_read(iocb, iov, nr_segs, pos); + + /* + * In strict cache mode we need to read from the server all the time + * if we don't have level II oplock because the server can delay mtime + * change - so we can't make a decision about inode invalidating. + * And we can also fail with pagereading if there are mandatory locks + * on pages affected by this read but not on the region from pos to + * pos+len-1. + */ + + for (i = 0; i < nr_segs; i++) { + retval = cifs_user_read(iocb->ki_filp, iov[i].iov_base, + iov[i].iov_len, &pos); + if (retval < 0) { + read = read ? read : retval; + break; + } + + read += retval; + } + + iocb->ki_pos = pos; + + return read; +} + static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, loff_t pos) { @@ -690,7 +730,7 @@ const struct inode_operations cifs_symlink_inode_ops = { const struct file_operations cifs_file_ops = { .read = do_sync_read, .write = do_sync_write, - .aio_read = generic_file_aio_read, + .aio_read = cifs_file_aio_read, .aio_write = cifs_file_aio_write, .open = cifs_open, .release = cifs_close, @@ -727,7 +767,7 @@ const struct file_operations cifs_file_direct_ops = { const struct file_operations cifs_file_nobrl_ops = { .read = do_sync_read, .write = do_sync_write, - .aio_read = generic_file_aio_read, + .aio_read = cifs_file_aio_read, .aio_write = cifs_file_aio_write, .open = cifs_open, .release = cifs_close,