diff options
-rw-r--r-- | usr/src/cmd/dfs.cmds/sharemgr/commands.c | 77 | ||||
-rw-r--r-- | usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c | 25 | ||||
-rw-r--r-- | usr/src/lib/libshare/common/libsharecore.c | 15 |
3 files changed, 70 insertions, 47 deletions
diff --git a/usr/src/cmd/dfs.cmds/sharemgr/commands.c b/usr/src/cmd/dfs.cmds/sharemgr/commands.c index 33a4a8eb25..ce70a92386 100644 --- a/usr/src/cmd/dfs.cmds/sharemgr/commands.c +++ b/usr/src/cmd/dfs.cmds/sharemgr/commands.c @@ -227,22 +227,44 @@ check_authorizations(char *instname, int flags) } /* - * enable_all_groups(list, setstate, online, update) - * Given a list of groups, enable each one found. If update is - * not NULL, then update all the shares for the protocol that was - * passed in. + * enable_group(group, updateproto) + * + * enable all the shares in the specified group. This is a helper for + * enable_all_groups in order to simplify regular and subgroup (zfs) + * disabling. Group has already been checked for non-NULL. */ -static int -enable_all_groups(struct list *work, int setstate, int online, char *update) + +static void +enable_group(sa_group_t group, char *updateproto) { sa_share_t share; + + for (share = sa_get_share(group, NULL); + share != NULL; + share = sa_get_next_share(share)) { + if (updateproto != NULL) + (void) sa_update_legacy(share, updateproto); + (void) sa_enable_share(share, NULL); + } +} + +/* + * enable_all_groups(list, setstate, online, updateproto) + * Given a list of groups, enable each one found. If updateproto + * is not NULL, then update all the shares for the protocol that + * was passed in. + */ +static int +enable_all_groups(struct list *work, int setstate, int online, + char *updateproto) +{ int ret = SA_OK; char instance[SA_MAX_NAME_LEN + sizeof (SA_SVC_FMRI_BASE) + 1]; char *state; char *name; char *zfs = NULL; - int dozfs = 0; sa_group_t group; + sa_group_t subgroup; while (work != NULL && ret == SA_OK) { group = (sa_group_t)work->item; @@ -256,16 +278,24 @@ enable_all_groups(struct list *work, int setstate, int online, char *update) if (ret == SA_OK) { /* if itemdata == NULL then the whole group */ if (work->itemdata == NULL) { - for (share = sa_get_share(group, NULL); - share != NULL; share = sa_get_next_share(share)) { - if (update != NULL) - (void) sa_update_legacy(share, update); - ret = sa_enable_share(share, NULL); + zfs = sa_get_group_attr(group, "zfs"); + /* + * if the share is managed by ZFS, don't + * update any of the protocols since ZFS is + * handling this. updateproto will contain + * the name of the protocol that we want to + * update legacy files for. + */ + enable_group(group, zfs == NULL ? updateproto : NULL); + for (subgroup = sa_get_sub_group(group); subgroup != NULL; + subgroup = sa_get_next_group(subgroup)) { + /* never update legacy for ZFS subgroups */ + enable_group(subgroup, NULL); } } if (online) { - name = sa_get_group_attr(group, "name"); zfs = sa_get_group_attr(group, "zfs"); + name = sa_get_group_attr(group, "name"); if (name != NULL) { if (zfs == NULL) { (void) snprintf(instance, sizeof (instance), @@ -278,20 +308,12 @@ enable_all_groups(struct list *work, int setstate, int online, char *update) free(state); } } else { - dozfs++; sa_free_attr_string(zfs); zfs = NULL; } if (name != NULL) sa_free_attr_string(name); } - } else { - zfs = sa_get_group_attr(group, "zfs"); - if (zfs != NULL) { - dozfs++; - sa_free_attr_string(zfs); - zfs = NULL; - } } work = work->next; } @@ -299,19 +321,6 @@ enable_all_groups(struct list *work, int setstate, int online, char *update) if (ret == SA_OK) { ret = sa_update_config(); } - /* do ZFS last to allow everything to get updated */ - if (ret == SA_OK && dozfs) { - FILE *sys; - int err; - sys = popen(ZFS_SHAREALL, "r"); - if (sys != NULL) { - err = pclose(sys); - if (err != 0) - ret = SA_SYSTEM_ERR; - } else { - ret = SA_SYSTEM_ERR; - } - } return (ret); } diff --git a/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c b/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c index 8c57470d96..16e7ac891f 100644 --- a/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c +++ b/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c @@ -67,15 +67,6 @@ main(int argc, char *argv[]) (void) textdomain(TEXT_DOMAIN); /* - * initialize the plugin architecture. - * Plugins are needed in the event of a global help - * request. - */ - - sa_init(SA_INIT_SHARE_API); - optind = 1; /* reset to beginning */ - - /* * parse enough of command line to get protocol, if any. * Note that options need to come "after" the subcommand. */ @@ -108,7 +99,23 @@ main(int argc, char *argv[]) /* * now have enough to parse rest of command line + * + * First, initialize the plugin architecture. + * Plugins are needed in the event of a global help + * request. + * + * reset optind to 1 so the parsing that takes place in + * sa_init() will work correctly. + */ + + optind = 1; + sa_init(SA_INIT_SHARE_API); + + /* + * reset optind again since we will start parsing all over in + * the sub-commands. */ + optind = 1; rval = run_command(command, argc, argv, protocol); sa_fini(); diff --git a/usr/src/lib/libshare/common/libsharecore.c b/usr/src/lib/libshare/common/libsharecore.c index 9e1348feb6..4e48c9fede 100644 --- a/usr/src/lib/libshare/common/libsharecore.c +++ b/usr/src/lib/libshare/common/libsharecore.c @@ -126,6 +126,13 @@ fix_notice(xfs_sharelist_t *list) xfs_sharelist_t *item, *prev; int i; + if (list == NULL) { + /* zero length dfstab */ + list = alloc_sharelist(); + if (list == NULL) + return (NULL); + list->description = strdup("#\n"); + } if (list->path == NULL && list->description != NULL && strcmp(list->description, notice[0]) != 0) { for (prev = NULL, i = 0; i < DFSTAB_NOTICE_LINES; i++) { @@ -166,7 +173,7 @@ getdfstab(FILE *dfs) int argc; int c; static int line = 0; - xfs_sharelist_t *item, *first, *last; + xfs_sharelist_t *item = NULL, *first = NULL, *last; if (dfs != NULL) { first = NULL; @@ -254,7 +261,7 @@ getdfstab(FILE *dfs) } } } - if (item->fstype == NULL) + if (item != NULL && item->fstype == NULL) item->fstype = strdup("nfs"); /* this is the default */ } first = fix_notice(first); @@ -264,7 +271,7 @@ getdfstab(FILE *dfs) /* * finddfsentry(list, path) * - * Look for path in the zfs_sharelist_t list and return the tnry if it + * Look for path in the zfs_sharelist_t list and return the entry if it * exists. */ @@ -558,7 +565,7 @@ sa_delete_legacy(sa_share_t share) optionset = sa_get_next_optionset(optionset)) { char *proto = sa_get_optionset_attr(optionset, "type"); if (list != NULL && proto != NULL) - (void) remdfsentry(list, path, proto); + list = remdfsentry(list, path, proto); if (proto == NULL) ret = SA_NO_MEMORY; /* |