From patchwork Sun Apr 5 13:09:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 16426 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 n35DAJHX003887 for ; Sun, 5 Apr 2009 13:10:19 GMT Received: from dp.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id C39D9163C7E for ; Sun, 5 Apr 2009 13:10:00 +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.8 required=3.8 tests=AWL,BAYES_00, FORGED_RCVD_HELO,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.1.7 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from mx2.redhat.com (mx2.redhat.com [66.187.237.31]) by lists.samba.org (Postfix) with ESMTP id 410B2163C0C for ; Sun, 5 Apr 2009 13:09:06 +0000 (GMT) Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n35D9OaE001413; Sun, 5 Apr 2009 09:09:24 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n35D9P38027832; Sun, 5 Apr 2009 09:09:25 -0400 Received: from localhost.localdomain (vpn-12-24.rdu.redhat.com [10.11.12.24]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n35D9M62018279; Sun, 5 Apr 2009 09:09:23 -0400 From: Jeff Layton To: linux-cifs-client@lists.samba.org Date: Sun, 5 Apr 2009 09:09:20 -0400 Message-Id: <1238936961-6979-3-git-send-email-jlayton@redhat.com> In-Reply-To: <1238936961-6979-1-git-send-email-jlayton@redhat.com> References: <1238936961-6979-1-git-send-email-jlayton@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Cc: linux-fsdevel@vger.kernel.org Subject: [linux-cifs-client] [PATCH 2/3] cifs: add new cifs_iget_unix_basic function 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 Add a new cifs_iget_unix function that uses iget5_locked to identify inodes. This will compare inodes based on the UniqueId value that the server provides when unix extensions are enabled. We also have mounts with unix extensions use that value in the i_ino field (after hashing it down to 32-bits on a 32-bit arches). With this, we should then have proper hardlink detection and can eventually get rid of some nasty CIFS-specific hacks for handing them. Fixing the readdir codepath will be done in a later patch. Signed-off-by: Jeff Layton --- fs/cifs/cifsfs.h | 13 +++++ fs/cifs/cifsglob.h | 1 + fs/cifs/cifsproto.h | 4 +- fs/cifs/dir.c | 12 ++--- fs/cifs/inode.c | 138 +++++++++++++++++++++++++++++++++++---------------- 5 files changed, 117 insertions(+), 51 deletions(-) diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index fa3694e..aa4ffc0 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h @@ -24,6 +24,19 @@ #define ROOT_I 2 +/* + * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down + * so that it will fit. + */ +static inline ino_t +cifs_uniqueid_to_ino_t(u64 fileid) +{ + ino_t ino = (ino_t) fileid; + if (sizeof(ino_t) < sizeof(u64)) + ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8; + return ino; +} + extern struct file_system_type cifs_fs_type; extern const struct address_space_operations cifs_addr_ops; extern const struct address_space_operations cifs_addr_ops_smallbuf; diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 7ae1986..1bada66 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -371,6 +371,7 @@ struct cifsInodeInfo { bool oplockPending:1; bool delete_pending:1; /* DELETE_ON_CLOSE is set */ u64 server_eof; /* current file size on server */ + u64 uniqueid; /* server inode number */ struct inode vfs_inode; }; diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 4167716..51dfd51 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -99,8 +99,10 @@ extern int cifs_posix_open(char *full_path, struct inode **pinode, struct super_block *sb, int mode, int oflags, int *poplock, __u16 *pnetfid, int xid); extern void posix_fill_in_inode(struct inode *tmp_inode, - FILE_UNIX_BASIC_INFO *pData, int isNewInode); + FILE_UNIX_BASIC_INFO *pData); extern struct inode *cifs_new_inode(struct super_block *sb, __u64 *inum); +extern struct inode *cifs_iget_unix_basic(struct super_block *sb, + FILE_UNIX_BASIC_INFO *info); extern int cifs_get_inode_info(struct inode **pinode, const unsigned char *search_path, FILE_ALL_INFO *pfile_info, diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index d958044..be639ee 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -187,18 +187,16 @@ int cifs_posix_open(char *full_path, struct inode **pinode, if (!pinode) goto posix_open_ret; /* caller does not need info */ - if (*pinode == NULL) { - __u64 unique_id = le64_to_cpu(presp_data->UniqueId); - *pinode = cifs_new_inode(sb, &unique_id); - } + if (*pinode == NULL) + *pinode = cifs_iget_unix_basic(sb, presp_data); /* else an inode was passed in. Update its info, don't create one */ /* We do not need to close the file if new_inode fails since the caller will retry qpathinfo as long as inode is null */ - if (*pinode == NULL) + if (IS_ERR(*pinode)) { + rc = PTR_ERR(*pinode); goto posix_open_ret; - - posix_fill_in_inode(*pinode, presp_data, 1); + } posix_open_ret: kfree(presp_data); diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index b67c527..c30c318 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -272,15 +272,11 @@ int cifs_get_inode_info_unix(struct inode **pinode, } else if (rc) goto cgiiu_exit; - num_of_bytes = le64_to_cpu(find_data.NumOfBytes); - end_of_file = le64_to_cpu(find_data.EndOfFile); - /* get new inode */ if (*pinode == NULL) { - __u64 unique_id = le64_to_cpu(find_data.UniqueId); - *pinode = cifs_new_inode(sb, &unique_id); - if (*pinode == NULL) { - rc = -ENOMEM; + *pinode = cifs_iget_unix_basic(sb, &find_data); + if (IS_ERR(*pinode)) { + rc = PTR_ERR(*pinode); goto cgiiu_exit; } } @@ -291,18 +287,18 @@ int cifs_get_inode_info_unix(struct inode **pinode, cFYI(1, ("Old time %ld", cifsInfo->time)); cifsInfo->time = jiffies; cFYI(1, ("New time %ld", cifsInfo->time)); - /* this is ok to set on every inode revalidate */ - atomic_set(&cifsInfo->inUse, 1); - cifs_unix_info_to_inode(inode, &find_data, 0); + if (is_dfs_referral) + cifs_set_ops(inode, true); + num_of_bytes = le64_to_cpu(find_data.NumOfBytes); + end_of_file = le64_to_cpu(find_data.EndOfFile); if (num_of_bytes < end_of_file) cFYI(1, ("allocation size less than end of file")); cFYI(1, ("Size %ld and blocks %llu", (unsigned long) inode->i_size, (unsigned long long)inode->i_blocks)); - cifs_set_ops(inode, is_dfs_referral); cgiiu_exit: return rc; } @@ -698,33 +694,102 @@ char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb) return full_path; } +/* + * Compare the UniqueID in the FILE_UNIX_BASIC_INFO with the one associated + * with the inode + */ +static int +cifs_find_inode(struct inode *inode, void *opaque) +{ + u64 uniqueid = *((u64 *) opaque); + + if (CIFS_I(inode)->uniqueid != uniqueid) + return 0; + + return 1; +} + +static int +cifs_init_locked(struct inode *inode, void *opaque) +{ + u64 uniqueid = *((u64 *) opaque); + + CIFS_I(inode)->uniqueid = uniqueid; + return 0; +} + +/* + * Given a FILE_UNIX_BASIC_INFO struct, get the inode that matches the + * UniqueId or create a new inode. + */ +struct inode * +cifs_iget_locked(struct super_block *sb, u64 uniqueid) +{ + unsigned long hash; + struct inode *inode; + + cFYI(1,("looking for uniqueid=%lu\n", uniqueid)); + /* must hash down to 32-bits on 32-bit arch */ + hash = cifs_uniqueid_to_ino_t(uniqueid); + + inode = iget5_locked(sb, hash, cifs_find_inode, cifs_init_locked, + &uniqueid); + + if (inode && (inode->i_state & I_NEW)) + inode->i_ino = hash; + + return inode; +} + +struct inode * +cifs_iget_unix_basic(struct super_block *sb, FILE_UNIX_BASIC_INFO *info) +{ + struct inode *inode; + + inode = cifs_iget_locked(sb, le64_to_cpu(info->UniqueId)); + if (!inode) + return ERR_PTR(-ENOMEM); + + /* update inode since we have info in hand */ + posix_fill_in_inode(inode, info); + + if (inode->i_state & I_NEW) + unlock_new_inode(inode); + + return inode; +} + /* gets root inode */ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino) { int xid; struct cifs_sb_info *cifs_sb; - struct inode *inode; + struct inode *inode = NULL; long rc; char *full_path; - inode = iget_locked(sb, ino); - if (!inode) - return ERR_PTR(-ENOMEM); - if (!(inode->i_state & I_NEW)) - return inode; - - cifs_sb = CIFS_SB(inode->i_sb); + cifs_sb = CIFS_SB(sb); full_path = cifs_build_path_to_root(cifs_sb); if (full_path == NULL) return ERR_PTR(-ENOMEM); xid = GetXid(); - if (cifs_sb->tcon->unix_ext) - rc = cifs_get_inode_info_unix(&inode, full_path, inode->i_sb, - xid); - else + if (cifs_sb->tcon->unix_ext) { + rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid); + if (!inode) + return ERR_PTR(-ENOMEM); + } else { + inode = iget_locked(sb, ino); + if (!inode) + return ERR_PTR(-ENOMEM); + if (!(inode->i_state & I_NEW)) + return inode; + rc = cifs_get_inode_info(&inode, full_path, NULL, inode->i_sb, xid, NULL); + unlock_new_inode(inode); + } + if (rc && cifs_sb->tcon->ipc) { cFYI(1, ("ipc connection - fake read inode")); inode->i_mode |= S_IFDIR; @@ -740,7 +805,6 @@ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino) return ERR_PTR(rc); } - unlock_new_inode(inode); kfree(full_path); /* can not call macro FreeXid here since in a void func @@ -1056,8 +1120,7 @@ out_reval: return rc; } -void posix_fill_in_inode(struct inode *tmp_inode, - FILE_UNIX_BASIC_INFO *pData, int isNewInode) +void posix_fill_in_inode(struct inode *tmp_inode, FILE_UNIX_BASIC_INFO *pData) { struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode); loff_t local_size; @@ -1073,15 +1136,11 @@ void posix_fill_in_inode(struct inode *tmp_inode, cifs_unix_info_to_inode(tmp_inode, pData, 1); cifs_set_ops(tmp_inode, false); - if (!S_ISREG(tmp_inode->i_mode)) - return; - /* - * No sense invalidating pages for new inode - * since we we have not started caching - * readahead file data yet. + * No sense invalidating pages for new inode since we we have not + * started caching readahead file data yet. */ - if (isNewInode) + if (!S_ISREG(tmp_inode->i_mode) || tmp_inode->i_state & I_NEW) return; if (timespec_equal(&tmp_inode->i_mtime, &local_mtime) && @@ -1089,7 +1148,7 @@ void posix_fill_in_inode(struct inode *tmp_inode, cFYI(1, ("inode exists but unchanged")); } else { /* file may have changed on server */ - cFYI(1, ("invalidate inode, readdir detected change")); + cFYI(1, ("invalidate inode. change detected")); invalidate_remote_inode(tmp_inode); } } @@ -1140,7 +1199,6 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) cFYI(1, ("posix mkdir returned 0x%x", rc)); d_drop(direntry); } else { - __u64 unique_id; if (pInfo->Type == cpu_to_le32(-1)) { /* no return info, go query for it */ kfree(pInfo); @@ -1154,20 +1212,14 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) else direntry->d_op = &cifs_dentry_ops; - unique_id = le64_to_cpu(pInfo->UniqueId); - newinode = cifs_new_inode(inode->i_sb, &unique_id); - if (newinode == NULL) { + newinode = cifs_iget_unix_basic(inode->i_sb, pInfo); + if (IS_ERR(newinode)) { kfree(pInfo); goto mkdir_get_info; } - newinode->i_nlink = 2; d_instantiate(direntry, newinode); - /* we already checked in POSIXCreate whether - frame was long enough */ - posix_fill_in_inode(direntry->d_inode, - pInfo, 1 /* NewInode */); #ifdef CONFIG_CIFS_DEBUG2 cFYI(1, ("instantiated dentry %p %s to inode %p", direntry, direntry->d_name.name, newinode));