@@ -319,13 +319,25 @@ svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old)
319319
320320static struct cache_head * export_table [EXPORT_HASHMAX ];
321321
322+ static void nfsd4_fslocs_free (struct nfsd4_fs_locations * fsloc )
323+ {
324+ int i ;
325+
326+ for (i = 0 ; i < fsloc -> locations_count ; i ++ ) {
327+ kfree (fsloc -> locations [i ].path );
328+ kfree (fsloc -> locations [i ].hosts );
329+ }
330+ kfree (fsloc -> locations );
331+ }
332+
322333static void svc_export_put (struct kref * ref )
323334{
324335 struct svc_export * exp = container_of (ref , struct svc_export , h .ref );
325336 dput (exp -> ex_dentry );
326337 mntput (exp -> ex_mnt );
327338 auth_domain_put (exp -> ex_client );
328339 kfree (exp -> ex_path );
340+ nfsd4_fslocs_free (& exp -> ex_fslocs );
329341 kfree (exp );
330342}
331343
@@ -387,6 +399,69 @@ static int check_export(struct inode *inode, int flags)
387399
388400}
389401
402+ #ifdef CONFIG_NFSD_V4
403+
404+ static int
405+ fsloc_parse (char * * mesg , char * buf , struct nfsd4_fs_locations * fsloc )
406+ {
407+ int len ;
408+ int migrated , i , err ;
409+
410+ len = qword_get (mesg , buf , PAGE_SIZE );
411+ if (len != 5 || memcmp (buf , "fsloc" , 5 ))
412+ return 0 ;
413+
414+ /* listsize */
415+ err = get_int (mesg , & fsloc -> locations_count );
416+ if (err )
417+ return err ;
418+ if (fsloc -> locations_count > MAX_FS_LOCATIONS )
419+ return - EINVAL ;
420+ if (fsloc -> locations_count == 0 )
421+ return 0 ;
422+
423+ fsloc -> locations = kzalloc (fsloc -> locations_count
424+ * sizeof (struct nfsd4_fs_location ), GFP_KERNEL );
425+ if (!fsloc -> locations )
426+ return - ENOMEM ;
427+ for (i = 0 ; i < fsloc -> locations_count ; i ++ ) {
428+ /* colon separated host list */
429+ err = - EINVAL ;
430+ len = qword_get (mesg , buf , PAGE_SIZE );
431+ if (len <= 0 )
432+ goto out_free_all ;
433+ err = - ENOMEM ;
434+ fsloc -> locations [i ].hosts = kstrdup (buf , GFP_KERNEL );
435+ if (!fsloc -> locations [i ].hosts )
436+ goto out_free_all ;
437+ err = - EINVAL ;
438+ /* slash separated path component list */
439+ len = qword_get (mesg , buf , PAGE_SIZE );
440+ if (len <= 0 )
441+ goto out_free_all ;
442+ err = - ENOMEM ;
443+ fsloc -> locations [i ].path = kstrdup (buf , GFP_KERNEL );
444+ if (!fsloc -> locations [i ].path )
445+ goto out_free_all ;
446+ }
447+ /* migrated */
448+ err = get_int (mesg , & migrated );
449+ if (err )
450+ goto out_free_all ;
451+ err = - EINVAL ;
452+ if (migrated < 0 || migrated > 1 )
453+ goto out_free_all ;
454+ fsloc -> migrated = migrated ;
455+ return 0 ;
456+ out_free_all :
457+ nfsd4_fslocs_free (fsloc );
458+ return err ;
459+ }
460+
461+ #else /* CONFIG_NFSD_V4 */
462+ static inline int fsloc_parse (char * * mesg , char * buf , struct nfsd4_fs_locations * fsloc ) { return 0 ; }
463+ #endif
464+
390465static int svc_export_parse (struct cache_detail * cd , char * mesg , int mlen )
391466{
392467 /* client path expiry [flags anonuid anongid fsid] */
@@ -441,6 +516,11 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
441516 if (exp .h .expiry_time == 0 )
442517 goto out ;
443518
519+ /* fs locations */
520+ exp .ex_fslocs .locations = NULL ;
521+ exp .ex_fslocs .locations_count = 0 ;
522+ exp .ex_fslocs .migrated = 0 ;
523+
444524 /* flags */
445525 err = get_int (& mesg , & an_int );
446526 if (err == - ENOENT )
@@ -466,6 +546,10 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
466546
467547 err = check_export (nd .dentry -> d_inode , exp .ex_flags );
468548 if (err ) goto out ;
549+
550+ err = fsloc_parse (& mesg , buf , & exp .ex_fslocs );
551+ if (err )
552+ goto out ;
469553 }
470554
471555 expp = svc_export_lookup (& exp );
@@ -489,7 +573,8 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
489573 return err ;
490574}
491575
492- static void exp_flags (struct seq_file * m , int flag , int fsid , uid_t anonu , uid_t anong );
576+ static void exp_flags (struct seq_file * m , int flag , int fsid ,
577+ uid_t anonu , uid_t anong , struct nfsd4_fs_locations * fslocs );
493578
494579static int svc_export_show (struct seq_file * m ,
495580 struct cache_detail * cd ,
@@ -508,8 +593,8 @@ static int svc_export_show(struct seq_file *m,
508593 seq_putc (m , '(' );
509594 if (test_bit (CACHE_VALID , & h -> flags ) &&
510595 !test_bit (CACHE_NEGATIVE , & h -> flags ))
511- exp_flags (m , exp -> ex_flags , exp -> ex_fsid ,
512- exp -> ex_anon_uid , exp -> ex_anon_gid );
596+ exp_flags (m , exp -> ex_flags , exp -> ex_fsid ,
597+ exp -> ex_anon_uid , exp -> ex_anon_gid , & exp -> ex_fslocs );
513598 seq_puts (m , ")\n" );
514599 return 0 ;
515600}
@@ -532,6 +617,9 @@ static void svc_export_init(struct cache_head *cnew, struct cache_head *citem)
532617 new -> ex_dentry = dget (item -> ex_dentry );
533618 new -> ex_mnt = mntget (item -> ex_mnt );
534619 new -> ex_path = NULL ;
620+ new -> ex_fslocs .locations = NULL ;
621+ new -> ex_fslocs .locations_count = 0 ;
622+ new -> ex_fslocs .migrated = 0 ;
535623}
536624
537625static void export_update (struct cache_head * cnew , struct cache_head * citem )
@@ -545,6 +633,12 @@ static void export_update(struct cache_head *cnew, struct cache_head *citem)
545633 new -> ex_fsid = item -> ex_fsid ;
546634 new -> ex_path = item -> ex_path ;
547635 item -> ex_path = NULL ;
636+ new -> ex_fslocs .locations = item -> ex_fslocs .locations ;
637+ item -> ex_fslocs .locations = NULL ;
638+ new -> ex_fslocs .locations_count = item -> ex_fslocs .locations_count ;
639+ item -> ex_fslocs .locations_count = 0 ;
640+ new -> ex_fslocs .migrated = item -> ex_fslocs .migrated ;
641+ item -> ex_fslocs .migrated = 0 ;
548642}
549643
550644static struct cache_head * svc_export_alloc (void )
@@ -1159,7 +1253,8 @@ static struct flags {
11591253 { 0 , {"" , "" }}
11601254};
11611255
1162- static void exp_flags (struct seq_file * m , int flag , int fsid , uid_t anonu , uid_t anong )
1256+ static void exp_flags (struct seq_file * m , int flag , int fsid ,
1257+ uid_t anonu , uid_t anong , struct nfsd4_fs_locations * fsloc )
11631258{
11641259 int first = 0 ;
11651260 struct flags * flg ;
@@ -1175,6 +1270,21 @@ static void exp_flags(struct seq_file *m, int flag, int fsid, uid_t anonu, uid_t
11751270 seq_printf (m , "%sanonuid=%d" , first ++ ?"," :"" , anonu );
11761271 if (anong != (gid_t )- 2 && anong != (0x10000 - 2 ))
11771272 seq_printf (m , "%sanongid=%d" , first ++ ?"," :"" , anong );
1273+ if (fsloc && fsloc -> locations_count > 0 ) {
1274+ char * loctype = (fsloc -> migrated ) ? "refer" : "replicas" ;
1275+ int i ;
1276+
1277+ seq_printf (m , "%s%s=" , first ++ ?"," :"" , loctype );
1278+ seq_escape (m , fsloc -> locations [0 ].path , ",;@ \t\n\\" );
1279+ seq_putc (m , '@' );
1280+ seq_escape (m , fsloc -> locations [0 ].hosts , ",;@ \t\n\\" );
1281+ for (i = 1 ; i < fsloc -> locations_count ; i ++ ) {
1282+ seq_putc (m , ';' );
1283+ seq_escape (m , fsloc -> locations [i ].path , ",;@ \t\n\\" );
1284+ seq_putc (m , '@' );
1285+ seq_escape (m , fsloc -> locations [i ].hosts , ",;@ \t\n\\" );
1286+ }
1287+ }
11781288}
11791289
11801290static int e_show (struct seq_file * m , void * p )
0 commit comments