Skip to content

Commit c2dd137

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
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 <[email protected]>
1 parent b8a8a0d commit c2dd137

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

fs/nfs/unlink.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,14 @@ nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
444444
return rpc_run_task(&task_setup_data);
445445
}
446446

447+
#define SILLYNAME_PREFIX ".nfs"
448+
#define SILLYNAME_PREFIX_LEN ((unsigned)sizeof(SILLYNAME_PREFIX) - 1)
449+
#define SILLYNAME_FILEID_LEN ((unsigned)sizeof(u64) << 1)
450+
#define SILLYNAME_COUNTER_LEN ((unsigned)sizeof(unsigned int) << 1)
451+
#define SILLYNAME_LEN (SILLYNAME_PREFIX_LEN + \
452+
SILLYNAME_FILEID_LEN + \
453+
SILLYNAME_COUNTER_LEN)
454+
447455
/**
448456
* nfs_sillyrename - Perform a silly-rename of a dentry
449457
* @dir: inode of directory that contains dentry
@@ -469,10 +477,8 @@ int
469477
nfs_sillyrename(struct inode *dir, struct dentry *dentry)
470478
{
471479
static unsigned int sillycounter;
472-
const int fileidsize = sizeof(NFS_FILEID(dentry->d_inode))*2;
473-
const int countersize = sizeof(sillycounter)*2;
474-
const int slen = sizeof(".nfs")+fileidsize+countersize-1;
475-
char silly[slen+1];
480+
unsigned char silly[SILLYNAME_LEN + 1];
481+
unsigned long long fileid;
476482
struct dentry *sdentry;
477483
struct rpc_task *task;
478484
int error = -EIO;
@@ -489,20 +495,20 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
489495
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
490496
goto out;
491497

492-
sprintf(silly, ".nfs%*.*Lx",
493-
fileidsize, fileidsize,
494-
(unsigned long long)NFS_FILEID(dentry->d_inode));
498+
fileid = NFS_FILEID(dentry->d_inode);
495499

496500
/* Return delegation in anticipation of the rename */
497501
NFS_PROTO(dentry->d_inode)->return_delegation(dentry->d_inode);
498502

499503
sdentry = NULL;
500504
do {
501-
char *suffix = silly + slen - countersize;
502-
505+
int slen;
503506
dput(sdentry);
504507
sillycounter++;
505-
sprintf(suffix, "%*.*x", countersize, countersize, sillycounter);
508+
slen = scnprintf(silly, sizeof(silly),
509+
SILLYNAME_PREFIX "%0*llx%0*x",
510+
SILLYNAME_FILEID_LEN, fileid,
511+
SILLYNAME_COUNTER_LEN, sillycounter);
506512

507513
dfprintk(VFS, "NFS: trying to rename %s to %s\n",
508514
dentry->d_name.name, silly);

0 commit comments

Comments
 (0)