Multiple entries in ZFS "sharenfs" property?

Willem Jan Withagen wjw at digiware.nl
Mon Aug 3 09:33:00 UTC 2015


On 2-8-2015 22:56, Willem Jan Withagen wrote:
> On 2-8-2015 20:08, Lev Serebryakov wrote:
>> Hello Willem,
>>
>> Sunday, August 2, 2015, 1:49:54 PM, you wrote:
>>>>    Is it possible to put multiple entries (for multiple networks) into
>>>> "sharenfs" property for ZFS filesystem?
>>
>>> Something like?
>>>
>>> I think I just did it by putting the text between '' 's:
>>>          ' <volume>
>>
>>> Which then ends up in /etc/zfs/exports:
>>> /home/wjw  -alldirs -maproot=0 -network 192.168.10.0 -mask 255.255.252.0
>>   I need 4 such lines per FS (with different -network / -mask arguments). One line works. Four lines don't.
>
> Hi Lev,
>
> Nope, that doesn't work, as far as I can tell.
> You'd have to revert to editting /etc/exports.
>
> Or hack on 'zfs set sharenfs' to generate multiple lines, in some sort
> of format. Like making ';' a line separator, and then prefix each part
> with the volume we are modifying.
>
> Place to give it a go are in:
> cddl/compat/opensolaris/misc/fsshare.c:213
>          if (share) {
>                  fprintf(newfd, "%s\t%s\n", mountpoint,
>                      translate_opts(shareopts));
>          }
> And there split the shareopts on the split char (eg. ';') in several
> shareopts and then loop over them. Disadvantage is that the max length
> op the options is: MAXPATHLEN. So you can easily run out of space if you
> have many exports to do.

Could not resist...

--WjW

Perhaps something like:
Index: compat/opensolaris/misc/fsshare.c
===================================================================
--- compat/opensolaris/misc/fsshare.c   (revision 286222)
+++ compat/opensolaris/misc/fsshare.c   (working copy)
@@ -151,6 +151,7 @@
      int share)
  {
         char tmpfile[PATH_MAX];
+       char tmpshareopts[OPTSSIZE], *sharep, *sepp;
         char *line;
         FILE *newfd, *oldfd;
         int fd, error;
@@ -211,8 +212,25 @@
                 goto out;
         }
         if (share) {
-               fprintf(newfd, "%s\t%s\n", mountpoint,
-                   translate_opts(shareopts));
+               /* Feed shareopts in piecces to translate_opts */
+               if (strlcpy(tmpshareopts, shareopts, sizeof(tmpshareopts))
+                       >= sizeof(tmpshareopts))
+                       return (ENAMETOOLONG);
+               sharep = tmpshareopts;
+               do {
+                       sepp = strchr(sharep, ';');
+                       if ( sepp != sharep) {
+                               if (sepp != NULL)
+                                       *sepp = '\0';
+                               fprintf(newfd, "%s\t%s\n", mountpoint,
+                                       translate_opts(sharep));
+                               sharep= sepp+1;
+                       }
+               /*
+                * exit if no seperator was found
+                * then we just did the last iteration
+                */
+               } while (sepp != NULL);
         }

  out:




More information about the freebsd-fs mailing list