Skip to content

Commit

Permalink
cope with potentially long ->d_dname() output for shmem/hugetlb
Browse files Browse the repository at this point in the history
dynamic_dname() is both too much and too little for those - the
output may be well in excess of 64 bytes dynamic_dname() assumes
to be enough (thanks to ashmem feeding really long names to
shmem_file_setup()) and vsnprintf() is an overkill for those
guys.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Aug 24, 2013
1 parent b36f4be commit 118b230
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
11 changes: 11 additions & 0 deletions fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,17 @@ char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen,
return memcpy(buffer, temp, sz);
}

char *simple_dname(struct dentry *dentry, char *buffer, int buflen)
{
char *end = buffer + buflen;
/* these dentries are never renamed, so d_lock is not needed */
if (prepend(&end, &buflen, " (deleted)", 11) ||
prepend_name(&end, &buflen, &dentry->d_name) ||
prepend(&end, &buflen, "/", 1))
end = ERR_PTR(-ENAMETOOLONG);
return end;
}

/*
* Write full pathname from the root of the filesystem into the buffer.
*/
Expand Down
8 changes: 1 addition & 7 deletions fs/hugetlbfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,14 +926,8 @@ static int get_hstate_idx(int page_size_log)
return h - hstates;
}

static char *hugetlb_dname(struct dentry *dentry, char *buffer, int buflen)
{
return dynamic_dname(dentry, buffer, buflen, "/%s (deleted)",
dentry->d_name.name);
}

static struct dentry_operations anon_ops = {
.d_dname = hugetlb_dname
.d_dname = simple_dname
};

/*
Expand Down
1 change: 1 addition & 0 deletions include/linux/dcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ extern int d_validate(struct dentry *, struct dentry *);
* helper function for dentry_operations.d_dname() members
*/
extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
extern char *simple_dname(struct dentry *, char *, int);

extern char *__d_path(const struct path *, const struct path *, char *, int);
extern char *d_absolute_path(const struct path *, char *, int);
Expand Down
8 changes: 1 addition & 7 deletions mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2909,14 +2909,8 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);

/* common code */

static char *shmem_dname(struct dentry *dentry, char *buffer, int buflen)
{
return dynamic_dname(dentry, buffer, buflen, "/%s (deleted)",
dentry->d_name.name);
}

static struct dentry_operations anon_ops = {
.d_dname = shmem_dname
.d_dname = simple_dname
};

/**
Expand Down

0 comments on commit 118b230

Please sign in to comment.