From patchwork Fri Feb 20 20:51:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horst Reiterer X-Patchwork-Id: 8192 Received: from lists.samba.org (mail.samba.org [66.70.73.150]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n1KLDACF021953 for ; Fri, 20 Feb 2009 21:13:10 GMT Received: from dp.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 40E5A163C32 for ; Fri, 20 Feb 2009 21:12:57 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on dp.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.8 tests=BAYES_00, DNS_FROM_RFC_POST, SPF_PASS autolearn=no version=3.1.7 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org X-Greylist: delayed 1267 seconds by postgrey-1.24 at dp.samba.org; Fri, 20 Feb 2009 21:12:43 GMT Received: from ey-out-1920.google.com (ey-out-1920.google.com [74.125.78.146]) by lists.samba.org (Postfix) with ESMTP id DE8BA163B1A for ; Fri, 20 Feb 2009 21:12:43 +0000 (GMT) Received: by ey-out-1920.google.com with SMTP id 13so122439eye.14 for ; Fri, 20 Feb 2009 13:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:x-x-sender:to:cc :subject:message-id:user-agent:mime-version:content-type; bh=evvNxy1MR+V5snvp3s0WNq2FbrWuBkq7xzz1VC5Wvws=; b=B3wUtXNm00v33fUKiOliP7+2QgqVh/AlGk7E1x9xYtDFBWUa2NZqCxILcA+A41vkRI w4jO7E/2ywNd86d0psSunb4ngl5dl2cQYVfOR7fiORUpvc9mSZXofx2cy9mtNHbbZ0HB COXdlIUlT95zGVOEhq80Rt5hQst6mwfVjOgCU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:x-x-sender:to:cc:subject:message-id:user-agent :mime-version:content-type; b=J4jKOyUx/kaTqyZetb3ZIgMzqQAmN6N5bSPyWsScExHrbk9UqWVYVrIt/YFhMJi/tm M/ptapNzTTaJH9X4TZF+UzqGcQI9NUZfrj9JwerzXkXqyoj2GMhhGlhwyTJdF5q9mE3d Peo6lWraYFA+ZKtJBn06yk6Dx/4CQjlWkpzcc= Received: by 10.210.117.1 with SMTP id p1mr948563ebc.39.1235163107833; Fri, 20 Feb 2009 12:51:47 -0800 (PST) Received: from ?10.0.1.250? (cm89-77.liwest.at [212.241.89.77]) by mx.google.com with ESMTPS id 10sm5210930eyz.30.2009.02.20.12.51.47 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 20 Feb 2009 12:51:47 -0800 (PST) Date: Fri, 20 Feb 2009 21:51:46 +0100 (CET) From: Horst Reiterer X-X-Sender: horstreiterer@horst-reiterers-macbook-air.local To: smfrench@gmail.com Message-ID: User-Agent: Alpine 2.00 (OSX 1167 2008-08-23) MIME-Version: 1.0 Cc: linux-cifs-client@lists.samba.org, linux-kernel@vger.kernel.org Subject: [linux-cifs-client] [PATCH] fs/cifs: send SMB_COM_FLUSH in cifs_fsync X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org Errors-To: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org Hi, In contrast to the now-obsolete smbfs, cifs does not send SMB_COM_FLUSH in response to an explicit fsync(2) to guarantee that all volatile data is written to stable storage on the server side, provided the server honors the request (which, to my knowledge, is true for Windows and Samba with 'strict sync' enabled). This patch modifies the cifs_fsync implementation to restore the fsync-behavior of smbfs by triggering SMB_COM_FLUSH after sending outstanding data on the client side to the server. I inquired about this issue in the linux-cifs-client@lists.samba.org mailing list: On Tue, Feb 10, 2009 at 12:35 AM, Jeff Layton wrote: > Horst Reiterer wrote: > > Why was the explicit SMB_COM_FLUSH dropped in the new implementation? > > It's not that it was "removed" per-se, just never implemented. Patches > to add that capability would certainly be welcome. I tested the patch with 2.6.28.6 and 2.6.18 (backported) on x86_64. Please review and apply. Horst. Signed-off-by: Horst Reiterer diff -uprN linux-2.6.28.6/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c --- linux-2.6.28.6/fs/cifs/cifs_debug.c 2009-02-17 18:29:27.000000000 +0100 +++ b/fs/cifs/cifs_debug.c 2009-02-20 00:42:18.000000000 +0100 @@ -340,6 +340,8 @@ static int cifs_stats_proc_show(struct s seq_printf(m, "\nWrites: %d Bytes: %lld", atomic_read(&tcon->num_writes), (long long)(tcon->bytes_written)); + seq_printf(m, "\nFlushes: %d", + atomic_read(&tcon->num_flushes)); seq_printf(m, "\nLocks: %d HardLinks: %d " "Symlinks: %d", atomic_read(&tcon->num_locks), diff -uprN linux-2.6.28.6/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h --- linux-2.6.28.6/fs/cifs/cifsglob.h 2009-02-17 18:29:27.000000000 +0100 +++ b/fs/cifs/cifsglob.h 2009-02-20 00:42:18.000000000 +0100 @@ -246,6 +246,7 @@ struct cifsTconInfo { atomic_t num_smbs_sent; atomic_t num_writes; atomic_t num_reads; + atomic_t num_flushes; atomic_t num_oplock_brks; atomic_t num_opens; atomic_t num_closes; diff -uprN linux-2.6.28.6/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h --- linux-2.6.28.6/fs/cifs/cifspdu.h 2009-02-17 18:29:27.000000000 +0100 +++ b/fs/cifs/cifspdu.h 2009-02-20 00:42:18.000000000 +0100 @@ -43,6 +43,7 @@ #define SMB_COM_CREATE_DIRECTORY 0x00 /* trivial response */ #define SMB_COM_DELETE_DIRECTORY 0x01 /* trivial response */ #define SMB_COM_CLOSE 0x04 /* triv req/rsp, timestamp ignored */ +#define SMB_COM_FLUSH 0x05 /* triv req/rsp */ #define SMB_COM_DELETE 0x06 /* trivial response */ #define SMB_COM_RENAME 0x07 /* trivial response */ #define SMB_COM_QUERY_INFORMATION 0x08 /* aka getattr */ @@ -790,6 +791,12 @@ typedef struct smb_com_close_rsp { __u16 ByteCount; /* bct = 0 */ } __attribute__((packed)) CLOSE_RSP; +typedef struct smb_com_flush_req { + struct smb_hdr hdr; /* wct = 1 */ + __u16 FileID; + __u16 ByteCount; /* 0 */ +} __attribute__((packed)) FLUSH_REQ; + typedef struct smb_com_findclose_req { struct smb_hdr hdr; /* wct = 1 */ __u16 FileID; diff -uprN linux-2.6.28.6/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h --- linux-2.6.28.6/fs/cifs/cifsproto.h 2009-02-17 18:29:27.000000000 +0100 +++ b/fs/cifs/cifsproto.h 2009-02-20 00:42:18.000000000 +0100 @@ -277,6 +277,9 @@ extern int CIFSPOSIXCreate(const int xid extern int CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, const int smb_file_id); +extern int CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, + const int smb_file_id); + extern int CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, unsigned int count, const __u64 lseek, unsigned int *nbytes, char **buf, diff -uprN linux-2.6.28.6/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c --- linux-2.6.28.6/fs/cifs/cifssmb.c 2009-02-17 18:29:27.000000000 +0100 +++ b/fs/cifs/cifssmb.c 2009-02-20 00:42:18.000000000 +0100 @@ -1928,6 +1928,27 @@ CIFSSMBClose(const int xid, struct cifsT } int +CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id) +{ + int rc = 0; + FLUSH_REQ *pSMB = NULL; + cFYI(1, ("In CIFSSMBFlush")); + + rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); + if (rc) + return rc; + + pSMB->FileID = (__u16) smb_file_id; + pSMB->ByteCount = 0; + rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); + cifs_stats_inc(&tcon->num_flushes); + if (rc) + cERROR(1, ("Send error in Flush = %d", rc)); + + return rc; +} + +int CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, const char *fromName, const char *toName, const struct nls_table *nls_codepage, int remap) diff -uprN linux-2.6.28.6/fs/cifs/file.c b/fs/cifs/file.c --- linux-2.6.28.6/fs/cifs/file.c 2009-02-17 18:29:27.000000000 +0100 +++ b/fs/cifs/file.c 2009-02-20 00:42:18.000000000 +0100 @@ -1522,18 +1522,31 @@ int cifs_fsync(struct file *file, struct { int xid; int rc = 0; + struct cifs_sb_info *cifs_sb; + struct cifsTconInfo *pTcon; + struct cifsFileInfo *pSMBFile = + (struct cifsFileInfo *)file->private_data; struct inode *inode = file->f_path.dentry->d_inode; xid = GetXid(); + cifs_sb = CIFS_SB(inode->i_sb); + pTcon = cifs_sb->tcon; + cFYI(1, ("Sync file - name: %s datasync: 0x%x", dentry->d_name.name, datasync)); - rc = filemap_write_and_wait(inode->i_mapping); - if (rc == 0) { - rc = CIFS_I(inode)->write_behind_rc; - CIFS_I(inode)->write_behind_rc = 0; - } + if (pSMBFile) { + rc = filemap_write_and_wait(inode->i_mapping); + if (rc == 0) { + rc = CIFS_I(inode)->write_behind_rc; + CIFS_I(inode)->write_behind_rc = 0; + if (pTcon) + rc = CIFSSMBFlush(xid, pTcon, pSMBFile->netfid); + } + } else + rc = -EBADF; + FreeXid(xid); return rc; }