@@ -212,7 +212,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
212212 fileid_type = 2 ;
213213 } else
214214 fileid_type = fh -> fh_fileid_type ;
215-
215+
216216 if (fileid_type == 0 )
217217 dentry = dget (exp -> ex_dentry );
218218 else {
@@ -292,7 +292,7 @@ static inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
292292 __u32 * datap , int * maxsize )
293293{
294294 struct export_operations * nop = exp -> ex_mnt -> mnt_sb -> s_export_op ;
295-
295+
296296 if (dentry == exp -> ex_dentry ) {
297297 * maxsize = 0 ;
298298 return 0 ;
@@ -317,7 +317,8 @@ static inline void _fh_update_old(struct dentry *dentry,
317317}
318318
319319__be32
320- fh_compose (struct svc_fh * fhp , struct svc_export * exp , struct dentry * dentry , struct svc_fh * ref_fh )
320+ fh_compose (struct svc_fh * fhp , struct svc_export * exp , struct dentry * dentry ,
321+ struct svc_fh * ref_fh )
321322{
322323 /* ref_fh is a reference file handle.
323324 * if it is non-null and for the same filesystem, then we should compose
@@ -327,8 +328,8 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
327328 *
328329 */
329330
330- u8 ref_fh_version = 0 ;
331- u8 ref_fh_fsid_type = 0 ;
331+ u8 version = 1 ;
332+ u8 fsid_type = 0 ;
332333 struct inode * inode = dentry -> d_inode ;
333334 struct dentry * parent = dentry -> d_parent ;
334335 __u32 * datap ;
@@ -340,57 +341,52 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
340341 parent -> d_name .name , dentry -> d_name .name ,
341342 (inode ? inode -> i_ino : 0 ));
342343
344+ /* Choose filehandle version and fsid type based on
345+ * the reference filehandle (if it is in the same export)
346+ * or the export options.
347+ */
343348 if (ref_fh && ref_fh -> fh_export == exp ) {
344- ref_fh_version = ref_fh -> fh_handle .fh_version ;
345- if (ref_fh_version == 0xca )
346- ref_fh_fsid_type = 0 ;
349+ version = ref_fh -> fh_handle .fh_version ;
350+ if (version == 0xca )
351+ fsid_type = 0 ;
347352 else
348- ref_fh_fsid_type = ref_fh -> fh_handle .fh_fsid_type ;
349- if (ref_fh_fsid_type > 3 )
350- ref_fh_fsid_type = 0 ;
351-
352- /* make sure ref_fh type works for given export */
353- if (ref_fh_fsid_type == 1 &&
354- !(exp -> ex_flags & NFSEXP_FSID )) {
355- /* if we don't have an fsid, we cannot provide one... */
356- ref_fh_fsid_type = 0 ;
357- }
353+ fsid_type = ref_fh -> fh_handle .fh_fsid_type ;
354+ /* We know this version/type works for this export
355+ * so there is no need for further checks.
356+ */
358357 } else if (exp -> ex_flags & NFSEXP_FSID )
359- ref_fh_fsid_type = 1 ;
360-
361- if (!old_valid_dev (ex_dev ) && ref_fh_fsid_type == 0 ) {
358+ fsid_type = 1 ;
359+ else if (!old_valid_dev (ex_dev ))
362360 /* for newer device numbers, we must use a newer fsid format */
363- ref_fh_version = 1 ;
364- ref_fh_fsid_type = 3 ;
365- }
366- if (old_valid_dev (ex_dev ) &&
367- (ref_fh_fsid_type == 2 || ref_fh_fsid_type == 3 ))
368- /* must use type1 for smaller device numbers */
369- ref_fh_fsid_type = 0 ;
361+ fsid_type = 3 ;
362+ else
363+ fsid_type = 0 ;
370364
371365 if (ref_fh == fhp )
372366 fh_put (ref_fh );
373367
374368 if (fhp -> fh_locked || fhp -> fh_dentry ) {
375369 printk (KERN_ERR "fh_compose: fh %s/%s not initialized!\n" ,
376- parent -> d_name .name , dentry -> d_name .name );
370+ parent -> d_name .name , dentry -> d_name .name );
377371 }
378372 if (fhp -> fh_maxsize < NFS_FHSIZE )
379373 printk (KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n" ,
380- fhp -> fh_maxsize , parent -> d_name .name , dentry -> d_name .name );
374+ fhp -> fh_maxsize ,
375+ parent -> d_name .name , dentry -> d_name .name );
381376
382377 fhp -> fh_dentry = dget (dentry ); /* our internal copy */
383378 fhp -> fh_export = exp ;
384379 cache_get (& exp -> h );
385380
386- if (ref_fh_version == 0xca ) {
381+ if (version == 0xca ) {
387382 /* old style filehandle please */
388383 memset (& fhp -> fh_handle .fh_base , 0 , NFS_FHSIZE );
389384 fhp -> fh_handle .fh_size = NFS_FHSIZE ;
390385 fhp -> fh_handle .ofh_dcookie = 0xfeebbaca ;
391386 fhp -> fh_handle .ofh_dev = old_encode_dev (ex_dev );
392387 fhp -> fh_handle .ofh_xdev = fhp -> fh_handle .ofh_dev ;
393- fhp -> fh_handle .ofh_xino = ino_t_to_u32 (exp -> ex_dentry -> d_inode -> i_ino );
388+ fhp -> fh_handle .ofh_xino =
389+ ino_t_to_u32 (exp -> ex_dentry -> d_inode -> i_ino );
394390 fhp -> fh_handle .ofh_dirino = ino_t_to_u32 (parent_ino (dentry ));
395391 if (inode )
396392 _fh_update_old (dentry , exp , & fhp -> fh_handle );
@@ -399,38 +395,38 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, st
399395 fhp -> fh_handle .fh_version = 1 ;
400396 fhp -> fh_handle .fh_auth_type = 0 ;
401397 datap = fhp -> fh_handle .fh_auth + 0 ;
402- fhp -> fh_handle .fh_fsid_type = ref_fh_fsid_type ;
403- switch (ref_fh_fsid_type ) {
404- case 0 :
405- /*
406- * fsid_type 0:
407- * 2byte major, 2byte minor, 4byte inode
408- */
409- mk_fsid_v0 (datap , ex_dev ,
410- exp -> ex_dentry -> d_inode -> i_ino );
411- break ;
412- case 1 :
413- /* fsid_type 1 == 4 bytes filesystem id */
414- mk_fsid_v1 (datap , exp -> ex_fsid );
415- break ;
416- case 2 :
417- /*
418- * fsid_type 2:
419- * 4byte major, 4byte minor, 4byte inode
420- */
421- mk_fsid_v2 (datap , ex_dev ,
422- exp -> ex_dentry -> d_inode -> i_ino );
423- break ;
424- case 3 :
425- /*
426- * fsid_type 3:
427- * 4byte devicenumber, 4byte inode
428- */
429- mk_fsid_v3 (datap , ex_dev ,
430- exp -> ex_dentry -> d_inode -> i_ino );
431- break ;
398+ fhp -> fh_handle .fh_fsid_type = fsid_type ;
399+ switch (fsid_type ) {
400+ case 0 :
401+ /*
402+ * fsid_type 0:
403+ * 2byte major, 2byte minor, 4byte inode
404+ */
405+ mk_fsid_v0 (datap , ex_dev ,
406+ exp -> ex_dentry -> d_inode -> i_ino );
407+ break ;
408+ case 1 :
409+ /* fsid_type 1 == 4 bytes filesystem id */
410+ mk_fsid_v1 (datap , exp -> ex_fsid );
411+ break ;
412+ case 2 :
413+ /*
414+ * fsid_type 2:
415+ * 4byte major, 4byte minor, 4byte inode
416+ */
417+ mk_fsid_v2 (datap , ex_dev ,
418+ exp -> ex_dentry -> d_inode -> i_ino );
419+ break ;
420+ case 3 :
421+ /*
422+ * fsid_type 3:
423+ * 4byte devicenumber, 4byte inode
424+ */
425+ mk_fsid_v3 (datap , ex_dev ,
426+ exp -> ex_dentry -> d_inode -> i_ino );
427+ break ;
432428 }
433- len = key_len (ref_fh_fsid_type );
429+ len = key_len (fsid_type );
434430 datap += len /4 ;
435431 fhp -> fh_handle .fh_size = 4 + len ;
436432
@@ -457,7 +453,7 @@ fh_update(struct svc_fh *fhp)
457453{
458454 struct dentry * dentry ;
459455 __u32 * datap ;
460-
456+
461457 if (!fhp -> fh_dentry )
462458 goto out_bad ;
463459
0 commit comments