@@ -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}
0 commit comments