From patchwork Mon Dec 13 15:00:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 406492 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 oBDF1Ocq017890 for ; Mon, 13 Dec 2010 15:01:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754281Ab0LMPBb (ORCPT ); Mon, 13 Dec 2010 10:01:31 -0500 Received: from mail-ew0-f45.google.com ([209.85.215.45]:37976 "EHLO mail-ew0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752918Ab0LMPBa (ORCPT ); Mon, 13 Dec 2010 10:01:30 -0500 Received: by mail-ew0-f45.google.com with SMTP id 10so3926985ewy.4 for ; Mon, 13 Dec 2010 07:01:30 -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:in-reply-to:references; bh=YZUxE6Cboo+qN90o2hIXFSmlNuofTsZhTwHpVHti10M=; b=edt/xFUC28qBhV5RWOrGhWgZduZRrXYLEM2l1vwqF5w6X4YL+12jcjrHCi01PGYmM/ JiL8RQIVZKjp1jZExMokRx3j6ES7KHAZv1rvUsCNLDOci4QIAIquMQ4SG5MZxnPvrZMt WPo1X5uU8PEXMgozK+LeClwDk16ASZ7H5hyo0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=UUq9N8TM+wUqG+ZZo0xRTioiXC+IkG4bHE/EAd3K8IFH5eQc6Ivn2w3ng6I3URUJnF jOe/bKUMfZCatKHtpDnKcVgCd/g1RyWkrVyPdQLB17H/LvLG8YoJke05cht773rtE30e 4Sd7SuqIAMq5TbA1Cki776nSbBieZ4BXGDZ3w= Received: by 10.213.26.79 with SMTP id d15mr2558229ebc.35.1292252490254; Mon, 13 Dec 2010 07:01:30 -0800 (PST) Received: from localhost.localdomain (PPPoE-78-29-112-8.san.ru [78.29.112.8]) by mx.google.com with ESMTPS id w20sm148969eeh.0.2010.12.13.07.01.28 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 13 Dec 2010 07:01:29 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 6/7] CIFS: Implement cifs_strict_write Date: Mon, 13 Dec 2010 18:00:54 +0300 Message-Id: <1292252455-4025-6-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1292252455-4025-1-git-send-email-piastryyy@gmail.com> References: <1292252455-4025-1-git-send-email-piastryyy@gmail.com> 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]); Mon, 13 Dec 2010 15:01:31 +0000 (UTC) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index e3f0024..d5a9eb9 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -629,8 +629,53 @@ static ssize_t cifs_strict_read(struct kiocb *iocb, const struct iovec *iov, static ssize_t cifs_strict_write(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 written = 0; - /* BB */ + unsigned long i, len = 0; + char *buf, *offset; + + inode = iocb->ki_filp->f_path.dentry->d_inode; + + if (CIFS_I(inode)->clientCanCacheAll) + return generic_file_aio_write(iocb, iov, nr_segs, pos); + + cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb); + + /* + * In strict cache mode we need to write the data to the server exactly + * from the pos to pos+len-1 rather than flush all affected pages + * because it may cause a error with mandatory locks on these pages but + * not on the region from pos to ppos+len-1. + */ + + for (i = 0; i < nr_segs; i++) + len += iov[i].iov_len; + + buf = kmalloc(len, GFP_KERNEL); + + for (i = 0, offset = buf; i < nr_segs; i++) { + if (copy_from_user(offset, iov[i].iov_base, iov[i].iov_len)) { + kfree(buf); + return -EFAULT; + } + + offset += iov[i].iov_len; + } + + written = cifs_write((struct cifsFileInfo *)iocb->ki_filp->private_data, + buf, len, &pos); + if (written < 0) { + kfree(buf); + return written; + } + + iocb->ki_pos = pos; + + if (written > 0) + CIFS_I(inode)->invalid_mapping = true; + + kfree(buf); return written; } @@ -639,10 +684,17 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, { struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; ssize_t written; + int rc; written = generic_file_aio_write(iocb, iov, nr_segs, pos); - if (!CIFS_I(inode)->clientCanCacheAll) - filemap_fdatawrite(inode->i_mapping); + + if (CIFS_I(inode)->clientCanCacheAll) + return written; + + rc = filemap_fdatawrite(inode->i_mapping); + if (rc) + cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode); + return written; } diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 05f6446..62d083f 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -81,6 +81,9 @@ extern bool is_valid_oplock_break(struct smb_hdr *smb, extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); extern ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *poffset); +extern ssize_t cifs_write(struct cifsFileInfo *open_file, + const char *write_data, size_t write_size, + loff_t *poffset); extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); extern unsigned int smbCalcSize(struct smb_hdr *ptr); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 1f96326..2f63885 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1026,9 +1026,8 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data, return total_written; } -static ssize_t cifs_write(struct cifsFileInfo *open_file, - const char *write_data, size_t write_size, - loff_t *poffset) +ssize_t cifs_write(struct cifsFileInfo *open_file, const char *write_data, + size_t write_size, loff_t *poffset) { int rc = 0; unsigned int bytes_written = 0;