Skip to content

Commit b0b0382

Browse files
author
Al Viro
committed
->encode_fh() API change
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 <viro@zeniv.linux.org.uk>
1 parent 6d42e7e commit b0b0382

File tree

16 files changed

+94
-140
lines changed

16 files changed

+94
-140
lines changed

fs/btrfs/export.c

+4-11
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
parent_root_objectid) / 4)
1414
#define BTRFS_FID_SIZE_CONNECTABLE_ROOT (sizeof(struct btrfs_fid) / 4)
1515

16-
static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
17-
int connectable)
16+
static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
17+
struct inode *parent)
1818
{
1919
struct btrfs_fid *fid = (struct btrfs_fid *)fh;
20-
struct inode *inode = dentry->d_inode;
2120
int len = *max_len;
2221
int type;
2322

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

39-
if (connectable && !S_ISDIR(inode->i_mode)) {
40-
struct inode *parent;
38+
if (parent) {
4139
u64 parent_root_id;
4240

43-
spin_lock(&dentry->d_lock);
44-
45-
parent = dentry->d_parent->d_inode;
4641
fid->parent_objectid = BTRFS_I(parent)->location.objectid;
4742
fid->parent_gen = parent->i_generation;
4843
parent_root_id = BTRFS_I(parent)->root->objectid;
4944

50-
spin_unlock(&dentry->d_lock);
51-
5245
if (parent_root_id != fid->root_objectid) {
5346
fid->parent_root_objectid = parent_root_id;
5447
len = BTRFS_FID_SIZE_CONNECTABLE_ROOT;

fs/ceph/export.c

+2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ static struct dentry *ceph_fh_to_parent(struct super_block *sb,
247247
}
248248

249249
const struct export_operations ceph_export_ops = {
250+
#ifdef CEPH_BREAKAGE_FIXED
250251
.encode_fh = ceph_encode_fh,
252+
#endif
251253
.fh_to_dentry = ceph_fh_to_dentry,
252254
.fh_to_parent = ceph_fh_to_parent,
253255
};

fs/exportfs/expfs.c

+19-14
Original file line numberDiff line numberDiff line change
@@ -304,24 +304,23 @@ static int get_name(struct vfsmount *mnt, struct dentry *dentry,
304304

305305
/**
306306
* export_encode_fh - default export_operations->encode_fh function
307-
* @dentry: the dentry to encode
307+
* @inode: the object to encode
308308
* @fh: where to store the file handle fragment
309309
* @max_len: maximum length to store there
310-
* @connectable: whether to store parent information
310+
* @parent: parent directory inode, if wanted
311311
*
312312
* This default encode_fh function assumes that the 32 inode number
313313
* is suitable for locating an inode, and that the generation number
314314
* can be used to check that it is still valid. It places them in the
315315
* filehandle fragment where export_decode_fh expects to find them.
316316
*/
317-
static int export_encode_fh(struct dentry *dentry, struct fid *fid,
318-
int *max_len, int connectable)
317+
static int export_encode_fh(struct inode *inode, struct fid *fid,
318+
int *max_len, struct inode *parent)
319319
{
320-
struct inode * inode = dentry->d_inode;
321320
int len = *max_len;
322321
int type = FILEID_INO32_GEN;
323322

324-
if (connectable && (len < 4)) {
323+
if (parent && (len < 4)) {
325324
*max_len = 4;
326325
return 255;
327326
} else if (len < 2) {
@@ -332,14 +331,9 @@ static int export_encode_fh(struct dentry *dentry, struct fid *fid,
332331
len = 2;
333332
fid->i32.ino = inode->i_ino;
334333
fid->i32.gen = inode->i_generation;
335-
if (connectable && !S_ISDIR(inode->i_mode)) {
336-
struct inode *parent;
337-
338-
spin_lock(&dentry->d_lock);
339-
parent = dentry->d_parent->d_inode;
334+
if (parent) {
340335
fid->i32.parent_ino = parent->i_ino;
341336
fid->i32.parent_gen = parent->i_generation;
342-
spin_unlock(&dentry->d_lock);
343337
len = 4;
344338
type = FILEID_INO32_GEN_PARENT;
345339
}
@@ -352,11 +346,22 @@ int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, int *max_len,
352346
{
353347
const struct export_operations *nop = dentry->d_sb->s_export_op;
354348
int error;
349+
struct dentry *p = NULL;
350+
struct inode *inode = dentry->d_inode, *parent = NULL;
355351

352+
if (connectable && !S_ISDIR(inode->i_mode)) {
353+
p = dget_parent(dentry);
354+
/*
355+
* note that while p might've ceased to be our parent already,
356+
* it's still pinned by and still positive.
357+
*/
358+
parent = p->d_inode;
359+
}
356360
if (nop->encode_fh)
357-
error = nop->encode_fh(dentry, fid->raw, max_len, connectable);
361+
error = nop->encode_fh(inode, fid->raw, max_len, parent);
358362
else
359-
error = export_encode_fh(dentry, fid, max_len, connectable);
363+
error = export_encode_fh(inode, fid, max_len, parent);
364+
dput(p);
360365

361366
return error;
362367
}

fs/fat/inode.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,9 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
752752
}
753753

754754
static int
755-
fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
755+
fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent)
756756
{
757757
int len = *lenp;
758-
struct inode *inode = de->d_inode;
759758
u32 ipos_h, ipos_m, ipos_l;
760759

761760
if (len < 5) {
@@ -771,9 +770,9 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
771770
fh[1] = inode->i_generation;
772771
fh[2] = ipos_h;
773772
fh[3] = ipos_m | MSDOS_I(inode)->i_logstart;
774-
spin_lock(&de->d_lock);
775-
fh[4] = ipos_l | MSDOS_I(de->d_parent->d_inode)->i_logstart;
776-
spin_unlock(&de->d_lock);
773+
fh[4] = ipos_l;
774+
if (parent)
775+
fh[4] |= MSDOS_I(parent)->i_logstart;
777776
return 3;
778777
}
779778

fs/fuse/inode.c

+5-12
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,10 @@ static struct dentry *fuse_get_dentry(struct super_block *sb,
627627
return ERR_PTR(err);
628628
}
629629

630-
static int fuse_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
631-
int connectable)
630+
static int fuse_encode_fh(struct inode *inode, u32 *fh, int *max_len,
631+
struct inode *parent)
632632
{
633-
struct inode *inode = dentry->d_inode;
634-
bool encode_parent = connectable && !S_ISDIR(inode->i_mode);
635-
int len = encode_parent ? 6 : 3;
633+
int len = parent ? 6 : 3;
636634
u64 nodeid;
637635
u32 generation;
638636

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

651-
if (encode_parent) {
652-
struct inode *parent;
653-
654-
spin_lock(&dentry->d_lock);
655-
parent = dentry->d_parent->d_inode;
649+
if (parent) {
656650
nodeid = get_fuse_inode(parent)->nodeid;
657651
generation = parent->i_generation;
658-
spin_unlock(&dentry->d_lock);
659652

660653
fh[3] = (u32)(nodeid >> 32);
661654
fh[4] = (u32)(nodeid & 0xffffffff);
662655
fh[5] = generation;
663656
}
664657

665658
*max_len = len;
666-
return encode_parent ? 0x82 : 0x81;
659+
return parent ? 0x82 : 0x81;
667660
}
668661

669662
static struct dentry *fuse_fh_to_dentry(struct super_block *sb,

fs/gfs2/export.c

+5-12
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
#define GFS2_LARGE_FH_SIZE 8
2929
#define GFS2_OLD_FH_SIZE 10
3030

31-
static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len,
32-
int connectable)
31+
static int gfs2_encode_fh(struct inode *inode, __u32 *p, int *len,
32+
struct inode *parent)
3333
{
3434
__be32 *fh = (__force __be32 *)p;
35-
struct inode *inode = dentry->d_inode;
3635
struct super_block *sb = inode->i_sb;
3736
struct gfs2_inode *ip = GFS2_I(inode);
3837

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

53-
if (!connectable || inode == sb->s_root->d_inode)
52+
if (!parent || inode == sb->s_root->d_inode)
5453
return *len;
5554

56-
spin_lock(&dentry->d_lock);
57-
inode = dentry->d_parent->d_inode;
58-
ip = GFS2_I(inode);
59-
igrab(inode);
60-
spin_unlock(&dentry->d_lock);
55+
ip = GFS2_I(parent);
6156

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

68-
iput(inode);
69-
7063
return *len;
7164
}
7265

fs/isofs/export.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
107107
}
108108

109109
static int
110-
isofs_export_encode_fh(struct dentry *dentry,
110+
isofs_export_encode_fh(struct inode *inode,
111111
__u32 *fh32,
112112
int *max_len,
113-
int connectable)
113+
struct inode *parent)
114114
{
115-
struct inode * inode = dentry->d_inode;
116115
struct iso_inode_info * ei = ISOFS_I(inode);
117116
int len = *max_len;
118117
int type = 1;
@@ -124,7 +123,7 @@ isofs_export_encode_fh(struct dentry *dentry,
124123
* offset of the inode and the upper 16 bits of fh32[1] to
125124
* hold the offset of the parent.
126125
*/
127-
if (connectable && (len < 5)) {
126+
if (parent && (len < 5)) {
128127
*max_len = 5;
129128
return 255;
130129
} else if (len < 3) {
@@ -136,16 +135,12 @@ isofs_export_encode_fh(struct dentry *dentry,
136135
fh32[0] = ei->i_iget5_block;
137136
fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
138137
fh32[2] = inode->i_generation;
139-
if (connectable && !S_ISDIR(inode->i_mode)) {
140-
struct inode *parent;
138+
if (parent) {
141139
struct iso_inode_info *eparent;
142-
spin_lock(&dentry->d_lock);
143-
parent = dentry->d_parent->d_inode;
144140
eparent = ISOFS_I(parent);
145141
fh32[3] = eparent->i_iget5_block;
146142
fh16[3] = (__u16)eparent->i_iget5_offset; /* fh16 [sic] */
147143
fh32[4] = parent->i_generation;
148-
spin_unlock(&dentry->d_lock);
149144
len = 5;
150145
type = 2;
151146
}

fs/nilfs2/namei.c

+10-12
Original file line numberDiff line numberDiff line change
@@ -508,31 +508,29 @@ static struct dentry *nilfs_fh_to_parent(struct super_block *sb, struct fid *fh,
508508
return nilfs_get_dentry(sb, fid->cno, fid->parent_ino, fid->parent_gen);
509509
}
510510

511-
static int nilfs_encode_fh(struct dentry *dentry, __u32 *fh, int *lenp,
512-
int connectable)
511+
static int nilfs_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
512+
struct inode *parent)
513513
{
514514
struct nilfs_fid *fid = (struct nilfs_fid *)fh;
515-
struct inode *inode = dentry->d_inode;
516515
struct nilfs_root *root = NILFS_I(inode)->i_root;
517516
int type;
518517

519-
if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE ||
520-
(connectable && *lenp < NILFS_FID_SIZE_CONNECTABLE))
518+
if (parent && *lenp < NILFS_FID_SIZE_CONNECTABLE) {
519+
*lenp = NILFS_FID_SIZE_CONNECTABLE;
520+
return 255;
521+
}
522+
if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE) {
523+
*lenp = NILFS_FID_SIZE_NON_CONNECTABLE;
521524
return 255;
525+
}
522526

523527
fid->cno = root->cno;
524528
fid->ino = inode->i_ino;
525529
fid->gen = inode->i_generation;
526530

527-
if (connectable && !S_ISDIR(inode->i_mode)) {
528-
struct inode *parent;
529-
530-
spin_lock(&dentry->d_lock);
531-
parent = dentry->d_parent->d_inode;
531+
if (parent) {
532532
fid->parent_ino = parent->i_ino;
533533
fid->parent_gen = parent->i_generation;
534-
spin_unlock(&dentry->d_lock);
535-
536534
type = FILEID_NILFS_WITH_PARENT;
537535
*lenp = NILFS_FID_SIZE_CONNECTABLE;
538536
} else {

fs/ocfs2/export.c

+7-12
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,23 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
177177
return parent;
178178
}
179179

180-
static int ocfs2_encode_fh(struct dentry *dentry, u32 *fh_in, int *max_len,
181-
int connectable)
180+
static int ocfs2_encode_fh(struct inode *inode, u32 *fh_in, int *max_len,
181+
struct inode *parent)
182182
{
183-
struct inode *inode = dentry->d_inode;
184183
int len = *max_len;
185184
int type = 1;
186185
u64 blkno;
187186
u32 generation;
188187
__le32 *fh = (__force __le32 *) fh_in;
189188

189+
#ifdef TRACE_HOOKS_ARE_NOT_BRAINDEAD_IN_YOUR_OPINION
190+
#error "You go ahead and fix that mess, then. Somehow"
190191
trace_ocfs2_encode_fh_begin(dentry, dentry->d_name.len,
191192
dentry->d_name.name,
192193
fh, len, connectable);
194+
#endif
193195

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

214-
if (connectable && !S_ISDIR(inode->i_mode)) {
215-
struct inode *parent;
216-
217-
spin_lock(&dentry->d_lock);
218-
219-
parent = dentry->d_parent->d_inode;
216+
if (parent) {
220217
blkno = OCFS2_I(parent)->ip_blkno;
221218
generation = parent->i_generation;
222219

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

227-
spin_unlock(&dentry->d_lock);
228-
229224
len = 6;
230225
type = 2;
231226

0 commit comments

Comments
 (0)