NFS: Clean up nfs_sillyrename()
Optimise for the case where we only do one lookup. Clean up the code so it is obvious that silly[] is not a dynamic array. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
@@ -444,6 +444,14 @@ nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
|
|||||||
return rpc_run_task(&task_setup_data);
|
return rpc_run_task(&task_setup_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SILLYNAME_PREFIX ".nfs"
|
||||||
|
#define SILLYNAME_PREFIX_LEN ((unsigned)sizeof(SILLYNAME_PREFIX) - 1)
|
||||||
|
#define SILLYNAME_FILEID_LEN ((unsigned)sizeof(u64) << 1)
|
||||||
|
#define SILLYNAME_COUNTER_LEN ((unsigned)sizeof(unsigned int) << 1)
|
||||||
|
#define SILLYNAME_LEN (SILLYNAME_PREFIX_LEN + \
|
||||||
|
SILLYNAME_FILEID_LEN + \
|
||||||
|
SILLYNAME_COUNTER_LEN)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nfs_sillyrename - Perform a silly-rename of a dentry
|
* nfs_sillyrename - Perform a silly-rename of a dentry
|
||||||
* @dir: inode of directory that contains dentry
|
* @dir: inode of directory that contains dentry
|
||||||
@@ -469,10 +477,8 @@ int
|
|||||||
nfs_sillyrename(struct inode *dir, struct dentry *dentry)
|
nfs_sillyrename(struct inode *dir, struct dentry *dentry)
|
||||||
{
|
{
|
||||||
static unsigned int sillycounter;
|
static unsigned int sillycounter;
|
||||||
const int fileidsize = sizeof(NFS_FILEID(dentry->d_inode))*2;
|
unsigned char silly[SILLYNAME_LEN + 1];
|
||||||
const int countersize = sizeof(sillycounter)*2;
|
unsigned long long fileid;
|
||||||
const int slen = sizeof(".nfs")+fileidsize+countersize-1;
|
|
||||||
char silly[slen+1];
|
|
||||||
struct dentry *sdentry;
|
struct dentry *sdentry;
|
||||||
struct rpc_task *task;
|
struct rpc_task *task;
|
||||||
int error = -EIO;
|
int error = -EIO;
|
||||||
@@ -489,20 +495,20 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
|
|||||||
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
|
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
sprintf(silly, ".nfs%*.*Lx",
|
fileid = NFS_FILEID(dentry->d_inode);
|
||||||
fileidsize, fileidsize,
|
|
||||||
(unsigned long long)NFS_FILEID(dentry->d_inode));
|
|
||||||
|
|
||||||
/* Return delegation in anticipation of the rename */
|
/* Return delegation in anticipation of the rename */
|
||||||
NFS_PROTO(dentry->d_inode)->return_delegation(dentry->d_inode);
|
NFS_PROTO(dentry->d_inode)->return_delegation(dentry->d_inode);
|
||||||
|
|
||||||
sdentry = NULL;
|
sdentry = NULL;
|
||||||
do {
|
do {
|
||||||
char *suffix = silly + slen - countersize;
|
int slen;
|
||||||
|
|
||||||
dput(sdentry);
|
dput(sdentry);
|
||||||
sillycounter++;
|
sillycounter++;
|
||||||
sprintf(suffix, "%*.*x", countersize, countersize, sillycounter);
|
slen = scnprintf(silly, sizeof(silly),
|
||||||
|
SILLYNAME_PREFIX "%0*llx%0*x",
|
||||||
|
SILLYNAME_FILEID_LEN, fileid,
|
||||||
|
SILLYNAME_COUNTER_LEN, sillycounter);
|
||||||
|
|
||||||
dfprintk(VFS, "NFS: trying to rename %s to %s\n",
|
dfprintk(VFS, "NFS: trying to rename %s to %s\n",
|
||||||
dentry->d_name.name, silly);
|
dentry->d_name.name, silly);
|
||||||
|
|||||||
Reference in New Issue
Block a user