Skip to content

Commit

Permalink
->encode_fh() API change
Browse files Browse the repository at this point in the history
pass inode + parent's inode or NULL instead of dentry + bool saying
whether we want the parent or not.

NOTE: that needs ceph fix folded in.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed May 30, 2012
1 parent 6d42e7e commit b0b0382
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 140 deletions.
15 changes: 4 additions & 11 deletions fs/btrfs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
parent_root_objectid) / 4)
#define BTRFS_FID_SIZE_CONNECTABLE_ROOT (sizeof(struct btrfs_fid) / 4)

static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
int connectable)
static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
struct inode *parent)
{
struct btrfs_fid *fid = (struct btrfs_fid *)fh;
struct inode *inode = dentry->d_inode;
int len = *max_len;
int type;

if (connectable && (len < BTRFS_FID_SIZE_CONNECTABLE)) {
if (parent && (len < BTRFS_FID_SIZE_CONNECTABLE)) {
*max_len = BTRFS_FID_SIZE_CONNECTABLE;
return 255;
} else if (len < BTRFS_FID_SIZE_NON_CONNECTABLE) {
Expand All @@ -36,19 +35,13 @@ static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
fid->root_objectid = BTRFS_I(inode)->root->objectid;
fid->gen = inode->i_generation;

if (connectable && !S_ISDIR(inode->i_mode)) {
struct inode *parent;
if (parent) {
u64 parent_root_id;

spin_lock(&dentry->d_lock);

parent = dentry->d_parent->d_inode;
fid->parent_objectid = BTRFS_I(parent)->location.objectid;
fid->parent_gen = parent->i_generation;
parent_root_id = BTRFS_I(parent)->root->objectid;

spin_unlock(&dentry->d_lock);

if (parent_root_id != fid->root_objectid) {
fid->parent_root_objectid = parent_root_id;
len = BTRFS_FID_SIZE_CONNECTABLE_ROOT;
Expand Down
2 changes: 2 additions & 0 deletions fs/ceph/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ static struct dentry *ceph_fh_to_parent(struct super_block *sb,
}

const struct export_operations ceph_export_ops = {
#ifdef CEPH_BREAKAGE_FIXED
.encode_fh = ceph_encode_fh,
#endif
.fh_to_dentry = ceph_fh_to_dentry,
.fh_to_parent = ceph_fh_to_parent,
};
33 changes: 19 additions & 14 deletions fs/exportfs/expfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,23 @@ static int get_name(struct vfsmount *mnt, struct dentry *dentry,

/**
* export_encode_fh - default export_operations->encode_fh function
* @dentry: the dentry to encode
* @inode: the object to encode
* @fh: where to store the file handle fragment
* @max_len: maximum length to store there
* @connectable: whether to store parent information
* @parent: parent directory inode, if wanted
*
* This default encode_fh function assumes that the 32 inode number
* is suitable for locating an inode, and that the generation number
* can be used to check that it is still valid. It places them in the
* filehandle fragment where export_decode_fh expects to find them.
*/
static int export_encode_fh(struct dentry *dentry, struct fid *fid,
int *max_len, int connectable)
static int export_encode_fh(struct inode *inode, struct fid *fid,
int *max_len, struct inode *parent)
{
struct inode * inode = dentry->d_inode;
int len = *max_len;
int type = FILEID_INO32_GEN;

if (connectable && (len < 4)) {
if (parent && (len < 4)) {
*max_len = 4;
return 255;
} else if (len < 2) {
Expand All @@ -332,14 +331,9 @@ static int export_encode_fh(struct dentry *dentry, struct fid *fid,
len = 2;
fid->i32.ino = inode->i_ino;
fid->i32.gen = inode->i_generation;
if (connectable && !S_ISDIR(inode->i_mode)) {
struct inode *parent;

spin_lock(&dentry->d_lock);
parent = dentry->d_parent->d_inode;
if (parent) {
fid->i32.parent_ino = parent->i_ino;
fid->i32.parent_gen = parent->i_generation;
spin_unlock(&dentry->d_lock);
len = 4;
type = FILEID_INO32_GEN_PARENT;
}
Expand All @@ -352,11 +346,22 @@ int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, int *max_len,
{
const struct export_operations *nop = dentry->d_sb->s_export_op;
int error;
struct dentry *p = NULL;
struct inode *inode = dentry->d_inode, *parent = NULL;

if (connectable && !S_ISDIR(inode->i_mode)) {
p = dget_parent(dentry);
/*
* note that while p might've ceased to be our parent already,
* it's still pinned by and still positive.
*/
parent = p->d_inode;
}
if (nop->encode_fh)
error = nop->encode_fh(dentry, fid->raw, max_len, connectable);
error = nop->encode_fh(inode, fid->raw, max_len, parent);
else
error = export_encode_fh(dentry, fid, max_len, connectable);
error = export_encode_fh(inode, fid, max_len, parent);
dput(p);

return error;
}
Expand Down
9 changes: 4 additions & 5 deletions fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,9 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
}

static int
fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent)
{
int len = *lenp;
struct inode *inode = de->d_inode;
u32 ipos_h, ipos_m, ipos_l;

if (len < 5) {
Expand All @@ -771,9 +770,9 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
fh[1] = inode->i_generation;
fh[2] = ipos_h;
fh[3] = ipos_m | MSDOS_I(inode)->i_logstart;
spin_lock(&de->d_lock);
fh[4] = ipos_l | MSDOS_I(de->d_parent->d_inode)->i_logstart;
spin_unlock(&de->d_lock);
fh[4] = ipos_l;
if (parent)
fh[4] |= MSDOS_I(parent)->i_logstart;
return 3;
}

Expand Down
17 changes: 5 additions & 12 deletions fs/fuse/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,10 @@ static struct dentry *fuse_get_dentry(struct super_block *sb,
return ERR_PTR(err);
}

static int fuse_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
int connectable)
static int fuse_encode_fh(struct inode *inode, u32 *fh, int *max_len,
struct inode *parent)
{
struct inode *inode = dentry->d_inode;
bool encode_parent = connectable && !S_ISDIR(inode->i_mode);
int len = encode_parent ? 6 : 3;
int len = parent ? 6 : 3;
u64 nodeid;
u32 generation;

Expand All @@ -648,22 +646,17 @@ static int fuse_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
fh[1] = (u32)(nodeid & 0xffffffff);
fh[2] = generation;

if (encode_parent) {
struct inode *parent;

spin_lock(&dentry->d_lock);
parent = dentry->d_parent->d_inode;
if (parent) {
nodeid = get_fuse_inode(parent)->nodeid;
generation = parent->i_generation;
spin_unlock(&dentry->d_lock);

fh[3] = (u32)(nodeid >> 32);
fh[4] = (u32)(nodeid & 0xffffffff);
fh[5] = generation;
}

*max_len = len;
return encode_parent ? 0x82 : 0x81;
return parent ? 0x82 : 0x81;
}

static struct dentry *fuse_fh_to_dentry(struct super_block *sb,
Expand Down
17 changes: 5 additions & 12 deletions fs/gfs2/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
#define GFS2_LARGE_FH_SIZE 8
#define GFS2_OLD_FH_SIZE 10

static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len,
int connectable)
static int gfs2_encode_fh(struct inode *inode, __u32 *p, int *len,
struct inode *parent)
{
__be32 *fh = (__force __be32 *)p;
struct inode *inode = dentry->d_inode;
struct super_block *sb = inode->i_sb;
struct gfs2_inode *ip = GFS2_I(inode);

if (connectable && (*len < GFS2_LARGE_FH_SIZE)) {
if (parent && (*len < GFS2_LARGE_FH_SIZE)) {
*len = GFS2_LARGE_FH_SIZE;
return 255;
} else if (*len < GFS2_SMALL_FH_SIZE) {
Expand All @@ -50,23 +49,17 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len,
fh[3] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF);
*len = GFS2_SMALL_FH_SIZE;

if (!connectable || inode == sb->s_root->d_inode)
if (!parent || inode == sb->s_root->d_inode)
return *len;

spin_lock(&dentry->d_lock);
inode = dentry->d_parent->d_inode;
ip = GFS2_I(inode);
igrab(inode);
spin_unlock(&dentry->d_lock);
ip = GFS2_I(parent);

fh[4] = cpu_to_be32(ip->i_no_formal_ino >> 32);
fh[5] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF);
fh[6] = cpu_to_be32(ip->i_no_addr >> 32);
fh[7] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF);
*len = GFS2_LARGE_FH_SIZE;

iput(inode);

return *len;
}

Expand Down
13 changes: 4 additions & 9 deletions fs/isofs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
}

static int
isofs_export_encode_fh(struct dentry *dentry,
isofs_export_encode_fh(struct inode *inode,
__u32 *fh32,
int *max_len,
int connectable)
struct inode *parent)
{
struct inode * inode = dentry->d_inode;
struct iso_inode_info * ei = ISOFS_I(inode);
int len = *max_len;
int type = 1;
Expand All @@ -124,7 +123,7 @@ isofs_export_encode_fh(struct dentry *dentry,
* offset of the inode and the upper 16 bits of fh32[1] to
* hold the offset of the parent.
*/
if (connectable && (len < 5)) {
if (parent && (len < 5)) {
*max_len = 5;
return 255;
} else if (len < 3) {
Expand All @@ -136,16 +135,12 @@ isofs_export_encode_fh(struct dentry *dentry,
fh32[0] = ei->i_iget5_block;
fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
fh32[2] = inode->i_generation;
if (connectable && !S_ISDIR(inode->i_mode)) {
struct inode *parent;
if (parent) {
struct iso_inode_info *eparent;
spin_lock(&dentry->d_lock);
parent = dentry->d_parent->d_inode;
eparent = ISOFS_I(parent);
fh32[3] = eparent->i_iget5_block;
fh16[3] = (__u16)eparent->i_iget5_offset; /* fh16 [sic] */
fh32[4] = parent->i_generation;
spin_unlock(&dentry->d_lock);
len = 5;
type = 2;
}
Expand Down
22 changes: 10 additions & 12 deletions fs/nilfs2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,31 +508,29 @@ static struct dentry *nilfs_fh_to_parent(struct super_block *sb, struct fid *fh,
return nilfs_get_dentry(sb, fid->cno, fid->parent_ino, fid->parent_gen);
}

static int nilfs_encode_fh(struct dentry *dentry, __u32 *fh, int *lenp,
int connectable)
static int nilfs_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
struct inode *parent)
{
struct nilfs_fid *fid = (struct nilfs_fid *)fh;
struct inode *inode = dentry->d_inode;
struct nilfs_root *root = NILFS_I(inode)->i_root;
int type;

if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE ||
(connectable && *lenp < NILFS_FID_SIZE_CONNECTABLE))
if (parent && *lenp < NILFS_FID_SIZE_CONNECTABLE) {
*lenp = NILFS_FID_SIZE_CONNECTABLE;
return 255;
}
if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE) {
*lenp = NILFS_FID_SIZE_NON_CONNECTABLE;
return 255;
}

fid->cno = root->cno;
fid->ino = inode->i_ino;
fid->gen = inode->i_generation;

if (connectable && !S_ISDIR(inode->i_mode)) {
struct inode *parent;

spin_lock(&dentry->d_lock);
parent = dentry->d_parent->d_inode;
if (parent) {
fid->parent_ino = parent->i_ino;
fid->parent_gen = parent->i_generation;
spin_unlock(&dentry->d_lock);

type = FILEID_NILFS_WITH_PARENT;
*lenp = NILFS_FID_SIZE_CONNECTABLE;
} else {
Expand Down
19 changes: 7 additions & 12 deletions fs/ocfs2/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,23 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
return parent;
}

static int ocfs2_encode_fh(struct dentry *dentry, u32 *fh_in, int *max_len,
int connectable)
static int ocfs2_encode_fh(struct inode *inode, u32 *fh_in, int *max_len,
struct inode *parent)
{
struct inode *inode = dentry->d_inode;
int len = *max_len;
int type = 1;
u64 blkno;
u32 generation;
__le32 *fh = (__force __le32 *) fh_in;

#ifdef TRACE_HOOKS_ARE_NOT_BRAINDEAD_IN_YOUR_OPINION
#error "You go ahead and fix that mess, then. Somehow"
trace_ocfs2_encode_fh_begin(dentry, dentry->d_name.len,
dentry->d_name.name,
fh, len, connectable);
#endif

if (connectable && (len < 6)) {
if (parent && (len < 6)) {
*max_len = 6;
type = 255;
goto bail;
Expand All @@ -211,21 +213,14 @@ static int ocfs2_encode_fh(struct dentry *dentry, u32 *fh_in, int *max_len,
fh[1] = cpu_to_le32((u32)(blkno & 0xffffffff));
fh[2] = cpu_to_le32(generation);

if (connectable && !S_ISDIR(inode->i_mode)) {
struct inode *parent;

spin_lock(&dentry->d_lock);

parent = dentry->d_parent->d_inode;
if (parent) {
blkno = OCFS2_I(parent)->ip_blkno;
generation = parent->i_generation;

fh[3] = cpu_to_le32((u32)(blkno >> 32));
fh[4] = cpu_to_le32((u32)(blkno & 0xffffffff));
fh[5] = cpu_to_le32(generation);

spin_unlock(&dentry->d_lock);

len = 6;
type = 2;

Expand Down
Loading

0 comments on commit b0b0382

Please sign in to comment.