Re: Changing the precedence order of client exports in /etc/exports

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 25 Apr 2024, James Pearson wrote:
> Many years ago, I asked on this list if it was possible to change the
> precedence order of exports listed in /etc/exports where there is more
> than one possible match (see the thread at:
> https://marc.info/?l=linux-nfs&m=130565040627856&w=2) - and answer was
> 'No'
> 
> At that time, I used a simple hack to force the precedence order I
> required (by modifying the 'MCL' enum order in nfs-utils
> support/include/exportfs.h)
> 
> However, the issue has come up again for me, so I thought I would see
> if I could alter the precedence order by adding an exports 'priority='
> option as suggested later in the above thread
> 
> I started with the nfs-utils supplied with CentOS 7 (based on 1.3.0) -
> and added logic to lookup_export() to check for client specifications
> with a higher priority - but this didn't work - so looking for other
> places that looped through MCL types, I added similar logic in
> nfsd_fh() - which seems to work as I expected (I'm using NFSv3)
> 
> However, adding similar logic to the nfs-utils supplied with Rocky 9
> (based on 2.5.4) didn't work ...
> 
> But comparing the code in nfsd_fh() in v1.3.0 and nfsd_handle_fh() in
> v2.5.4, nfsd_fh() in v1.3.0 does the following towards the end of the
> function - whereas nfsd_handle_fh() in v2.5.4 doesn't:
> 
>         if (cache_export_ent(buf, sizeof(buf), dom, found, found_path) < 0)
>                 found = 0;
> 
> By adding the above lines at a similar place in nfsd_handle_fh() in
> v2.5.4, seems to 'fix' the issue and all works as I expected
> 
> I don't fully understand what is going on under the hood with all
> this, so no idea if what I've done is 'correct', or if there is a
> better way of doing what I'm trying to achieve ?
> 
> Below is a patch (made against the latest git nfs-utils) of what I've
> done - could anyone let me know if I'm going along the right lines (or
> not) ?

The restored cache_export_ent() call has to go.
You need to update init_exportent() to initialise the new field.
You probably need to make some changes to auth_authenticate_newcache().
Probably let the loop run all the way to MCL_MAXTYPES, and do a priority
comparison if you find a new possible match.
export_find() probably need some attention too.

If you it still doesn't work after addressing those, I'll have a look
and see if I can beat it into shape.

NeilBrown


> 
> (I apologize if the formatting of the patch gets mangled by Gmail)
> 
> Thanks
> 
> James Pearson
> 
> diff --git a/support/export/cache.c b/support/export/cache.c
> index 6c0a44a3..e9392d8e 100644
> --- a/support/export/cache.c
> +++ b/support/export/cache.c
> @@ -54,6 +54,8 @@ enum nfsd_fsid {
>         FSID_UUID16_INUM,
>  };
> 
> +static int cache_export_ent(char *buf, int buflen, char *domain,
> struct exportent *exp, char *path);
> +
>  #undef is_mountpoint
>  static int is_mountpoint(const char *path)
>  {
> @@ -877,6 +879,14 @@ static int nfsd_handle_fh(int f, char *bp, int blen)
>                                 xlog(L_WARNING, "%s and %s have same
> filehandle for %s, using first",
>                                      found_path, path, dom);
>                         } else {
> +                               /* same path, see if this one has a
> higher export priority */
> +                               if (exp->m_export.e_priority >
> found->e_priority) {
> +                                       found = &exp->m_export;
> +                                       free(found_path);
> +                                       found_path = strdup(path);
> +                                       if (found_path == NULL)
> +                                               goto out;
> +                               }
>                                 /* same path, if one is V4ROOT, choose
> the other */
>                                 if (found->e_flags & NFSEXP_V4ROOT) {
>                                         found = &exp->m_export;
> @@ -910,6 +920,12 @@ static int nfsd_handle_fh(int f, char *bp, int blen)
>                 goto out;
>         }
> 
> +       /* adding this here - to make sure priority export changes are
> +        * picked up (this used to be in 1.X versions ?)
> +        */
> +       if (cache_export_ent(buf, sizeof(buf), dom, found, found_path) < 0)
> +               found = 0;
> +
>         bp = buf; blen = sizeof(buf);
>         qword_add(&bp, &blen, dom);
>         qword_addint(&bp, &blen, fsidtype);
> @@ -1178,6 +1194,12 @@ lookup_export(char *dom, char *path, struct addrinfo *ai)
>                                 found_type = i;
>                                 continue;
>                         }
> +                       /* see if this one has a higher export priority */
> +                       if (exp->m_export.e_priority >
> found->m_export.e_priority) {
> +                               found = exp;
> +                               found_type = i;
> +                               continue;
> +                       }
>                         /* Always prefer non-V4ROOT exports */
>                         if (exp->m_export.e_flags & NFSEXP_V4ROOT)
>                                 continue;
> diff --git a/support/include/nfslib.h b/support/include/nfslib.h
> index eff2a486..ab22ecaf 100644
> --- a/support/include/nfslib.h
> +++ b/support/include/nfslib.h
> @@ -99,6 +99,7 @@ struct exportent {
>         unsigned int    e_ttl;
>         char *          e_realpath;
>         int             e_reexport;
> +       int             e_priority;
>  };
> 
>  struct rmtabent {
> diff --git a/support/nfs/exports.c b/support/nfs/exports.c
> index a6816e60..548063b8 100644
> --- a/support/nfs/exports.c
> +++ b/support/nfs/exports.c
> @@ -374,6 +374,9 @@ putexportent(struct exportent *ep)
>                                 fprintf(fp, "%d,", id[i]);
>         }
>         fprintf(fp, "anonuid=%d,anongid=%d", ep->e_anonuid, ep->e_anongid);
> +       if (ep->e_priority) {
> +               fprintf(fp, ",priority=%d", ep->e_priority);
> +       }
>         secinfo_show(fp, ep);
>         xprtsecinfo_show(fp, ep);
>         fprintf(fp, ")\n");
> @@ -834,6 +837,14 @@ bad_option:
>                                 setflags(NFSEXP_FSID, active, ep);
> 
>                         saw_reexport = 1;
> +               } else if (strncmp(opt, "priority=", 9) == 0) {
> +                       char *oe;
> +                       ep->e_priority = strtol(opt+9, &oe, 10);
> +                       if (opt[9]=='\0' || *oe != '\0') {
> +                               xlog(L_ERROR, "%s: %d: bad priority \"%s\"\n",
> +                                    flname, flline, opt);
> +                               goto bad_option;
> +                       }
>                 } else {
>                         xlog(L_ERROR, "%s:%d: unknown keyword \"%s\"\n",
>                                         flname, flline, opt);
> 
> 






[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux