summaryrefslogtreecommitdiff
path: root/usr/src/lib/libshare/common/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libshare/common/plugin.c')
-rw-r--r--usr/src/lib/libshare/common/plugin.c217
1 files changed, 113 insertions, 104 deletions
diff --git a/usr/src/lib/libshare/common/plugin.c b/usr/src/lib/libshare/common/plugin.c
index 83bc4d5d94..4079e24ff7 100644
--- a/usr/src/lib/libshare/common/plugin.c
+++ b/usr/src/lib/libshare/common/plugin.c
@@ -81,83 +81,90 @@ proto_plugin_init()
struct stat st;
/*
- * should walk "/usr/lib/fs/" for files of the form:
+ * Should walk "/usr/lib/fs/" for files of the form:
* libshare_*.so
*/
dir = opendir(SA_LIB_DIR);
if (dir != NULL) {
- while (ret == SA_OK && (dent = readdir(dir)) != NULL) {
- char path[MAXPATHLEN];
- char isa[MAXISALEN];
+ while (ret == SA_OK && (dent = readdir(dir)) != NULL) {
+ char path[MAXPATHLEN];
+ char isa[MAXISALEN];
#if defined(_LP64)
- if (sysinfo(SI_ARCHITECTURE_64, isa, MAXISALEN) == -1)
- isa[0] = '\0';
+ if (sysinfo(SI_ARCHITECTURE_64, isa, MAXISALEN) == -1)
+ isa[0] = '\0';
#else
- isa[0] = '\0';
+ isa[0] = '\0';
#endif
- (void) snprintf(path, MAXPATHLEN,
- "%s/%s/%s/libshare_%s.so.1",
- SA_LIB_DIR,
- dent->d_name,
- isa,
- dent->d_name);
- if (stat(path, &st) < 0) {
- /* file doesn't exist, so don't try to map it */
- continue;
- }
- dlhandle = dlopen(path, RTLD_FIRST|RTLD_LAZY);
- if (dlhandle != NULL) {
- plugin_ops = (struct sa_plugin_ops *)
- dlsym(dlhandle, "sa_plugin_ops");
- proto = (struct sa_proto_plugin *)
- calloc(1, sizeof (struct sa_proto_plugin));
- if (proto != NULL) {
- proto->plugin_ops = plugin_ops;
- proto->plugin_handle = dlhandle;
- num_protos++;
- proto->plugin_next = sap_proto_list;
- sap_proto_list = proto;
- } else {
- ret = SA_NO_MEMORY;
- }
- } else {
- (void) fprintf(stderr,
- dgettext(TEXT_DOMAIN,
+ (void) snprintf(path, MAXPATHLEN,
+ "%s/%s/%s/libshare_%s.so.1", SA_LIB_DIR,
+ dent->d_name, isa, dent->d_name);
+ /*
+ * If file doesn't exist, don't try to map it
+ */
+ if (stat(path, &st) < 0)
+ continue;
+
+ dlhandle = dlopen(path, RTLD_FIRST|RTLD_LAZY);
+ if (dlhandle != NULL) {
+ plugin_ops = (struct sa_plugin_ops *)
+ dlsym(dlhandle, "sa_plugin_ops");
+ proto = (struct sa_proto_plugin *)
+ calloc(1, sizeof (struct sa_proto_plugin));
+ if (proto != NULL) {
+ proto->plugin_ops = plugin_ops;
+ proto->plugin_handle = dlhandle;
+ num_protos++;
+ proto->plugin_next = sap_proto_list;
+ sap_proto_list = proto;
+ } else {
+ ret = SA_NO_MEMORY;
+ }
+ } else {
+ (void) fprintf(stderr,
+ dgettext(TEXT_DOMAIN,
"Error in plugin for protocol %s: %s\n"),
- dent->d_name, dlerror());
+ dent->d_name, dlerror());
+ }
}
- }
- (void) closedir(dir);
+ (void) closedir(dir);
}
if (ret == SA_OK) {
- sa_proto_handle.sa_proto =
- (char **)calloc(num_protos, sizeof (char *));
- sa_proto_handle.sa_ops =
- (struct sa_plugin_ops **)calloc(num_protos,
- sizeof (struct sa_plugin_ops *));
- if (sa_proto_handle.sa_proto != NULL &&
- sa_proto_handle.sa_ops != NULL) {
- int i;
- struct sa_proto_plugin *tmp;
- for (i = 0, tmp = sap_proto_list; i < num_protos;
- tmp = tmp->plugin_next) {
- err = 0;
- if (tmp->plugin_ops->sa_init != NULL)
- err = tmp->plugin_ops->sa_init();
- if (err == SA_OK) {
- /* only include if the init succeeded or was NULL */
- sa_proto_handle.sa_num_proto++;
- sa_proto_handle.sa_ops[i] = tmp->plugin_ops;
- sa_proto_handle.sa_proto[i] =
- tmp->plugin_ops->sa_protocol;
- i++;
- }
+ sa_proto_handle.sa_proto =
+ (char **)calloc(num_protos, sizeof (char *));
+ sa_proto_handle.sa_ops =
+ (struct sa_plugin_ops **)calloc(num_protos,
+ sizeof (struct sa_plugin_ops *));
+ if (sa_proto_handle.sa_proto != NULL &&
+ sa_proto_handle.sa_ops != NULL) {
+ int i;
+ struct sa_proto_plugin *tmp;
+
+ for (i = 0, tmp = sap_proto_list;
+ i < num_protos;
+ tmp = tmp->plugin_next) {
+ err = 0;
+ if (tmp->plugin_ops->sa_init != NULL)
+ err = tmp->plugin_ops->sa_init();
+ if (err == SA_OK) {
+ /*
+ * Only include if the init
+ * succeeded or was NULL
+ */
+ sa_proto_handle.sa_num_proto++;
+ sa_proto_handle.sa_ops[i] =
+ tmp->plugin_ops;
+ sa_proto_handle.sa_proto[i] =
+ tmp->plugin_ops->sa_protocol;
+ i++;
+ }
+ }
}
- }
} else {
- /* there was an error, so cleanup prior to return of failure. */
- proto_plugin_fini();
+ /*
+ * There was an error, so cleanup prior to return of failure.
+ */
+ proto_plugin_fini();
}
return (ret);
}
@@ -165,32 +172,33 @@ proto_plugin_init()
/*
* proto_plugin_fini()
*
- * uninitialize all the plugin modules.
+ * Uninitialize all the plugin modules.
*/
void
proto_plugin_fini()
{
/*
- * free up all the protocols, calling their fini, if there is
+ * Free up all the protocols, calling their fini, if there is
* one.
*/
while (sap_proto_list != NULL) {
- struct sa_proto_plugin *next;
- next = sap_proto_list->plugin_next;
- sap_proto_list->plugin_ops->sa_fini();
- if (sap_proto_list->plugin_handle != NULL)
- (void) dlclose(sap_proto_list->plugin_handle);
- free(sap_proto_list);
- sap_proto_list = next;
+ struct sa_proto_plugin *next;
+
+ next = sap_proto_list->plugin_next;
+ sap_proto_list->plugin_ops->sa_fini();
+ if (sap_proto_list->plugin_handle != NULL)
+ (void) dlclose(sap_proto_list->plugin_handle);
+ free(sap_proto_list);
+ sap_proto_list = next;
}
if (sa_proto_handle.sa_ops != NULL) {
- free(sa_proto_handle.sa_ops);
- sa_proto_handle.sa_ops = NULL;
+ free(sa_proto_handle.sa_ops);
+ sa_proto_handle.sa_ops = NULL;
}
if (sa_proto_handle.sa_proto != NULL) {
- free(sa_proto_handle.sa_proto);
- sa_proto_handle.sa_proto = NULL;
+ free(sa_proto_handle.sa_proto);
+ sa_proto_handle.sa_proto = NULL;
}
sa_proto_handle.sa_num_proto = 0;
}
@@ -208,10 +216,10 @@ find_protocol(char *proto)
int i;
if (proto != NULL) {
- for (i = 0; i < sa_proto_handle.sa_num_proto; i++) {
- if (strcmp(proto, sa_proto_handle.sa_proto[i]) == 0)
- return (sa_proto_handle.sa_ops[i]);
- }
+ for (i = 0; i < sa_proto_handle.sa_num_proto; i++) {
+ if (strcmp(proto, sa_proto_handle.sa_proto[i]) == 0)
+ return (sa_proto_handle.sa_ops[i]);
+ }
}
return (NULL);
}
@@ -229,7 +237,7 @@ sa_proto_share(char *proto, sa_share_t share)
int ret = SA_INVALID_PROTOCOL;
if (ops != NULL && ops->sa_share != NULL)
- ret = ops->sa_share(share);
+ ret = ops->sa_share(share);
return (ret);
}
@@ -246,14 +254,14 @@ sa_proto_unshare(sa_share_t share, char *proto, char *path)
int ret = SA_INVALID_PROTOCOL;
if (ops != NULL && ops->sa_unshare != NULL)
- ret = ops->sa_unshare(share, path);
+ ret = ops->sa_unshare(share, path);
return (ret);
}
/*
* sa_proto_valid_prop(proto, prop, opt)
*
- * check to see if the specified prop is valid for this protocol.
+ * Check to see if the specified prop is valid for this protocol.
*/
int
@@ -263,14 +271,14 @@ sa_proto_valid_prop(char *proto, sa_property_t prop, sa_optionset_t opt)
int ret = 0;
if (ops != NULL && ops->sa_valid_prop != NULL)
- ret = ops->sa_valid_prop(prop, opt);
+ ret = ops->sa_valid_prop(prop, opt);
return (ret);
}
/*
* sa_proto_valid_space(proto, space)
*
- * check if space is valid optionspace for proto.
+ * Check if space is valid optionspace for proto.
* Protocols that don't implement this don't support spaces.
*/
int
@@ -280,14 +288,14 @@ sa_proto_valid_space(char *proto, char *token)
int ret = 0;
if (ops != NULL && ops->sa_valid_space != NULL)
- ret = ops->sa_valid_space(token);
+ ret = ops->sa_valid_space(token);
return (ret);
}
/*
* sa_proto_space_alias(proto, space)
*
- * if the name for space is an alias, return its proper name. This is
+ * If the name for space is an alias, return its proper name. This is
* used to translate "default" values into proper form.
*/
char *
@@ -297,7 +305,7 @@ sa_proto_space_alias(char *proto, char *space)
char *ret = space;
if (ops != NULL && ops->sa_space_alias != NULL)
- ret = ops->sa_space_alias(space);
+ ret = ops->sa_space_alias(space);
return (ret);
}
@@ -315,7 +323,7 @@ sa_proto_security_prop(char *proto, char *token)
int ret = 0;
if (ops != NULL && ops->sa_security_prop != NULL)
- ret = ops->sa_security_prop(token);
+ ret = ops->sa_security_prop(token);
return (ret);
}
@@ -333,7 +341,7 @@ sa_proto_legacy_opts(char *proto, sa_group_t group, char *options)
int ret = SA_INVALID_PROTOCOL;
if (ops != NULL && ops->sa_legacy_opts != NULL)
- ret = ops->sa_legacy_opts(group, options);
+ ret = ops->sa_legacy_opts(group, options);
return (ret);
}
@@ -351,7 +359,7 @@ sa_proto_legacy_format(char *proto, sa_group_t group, int hier)
char *ret = NULL;
if (ops != NULL && ops->sa_legacy_format != NULL)
- ret = ops->sa_legacy_format(group, hier);
+ ret = ops->sa_legacy_format(group, hier);
return (ret);
}
@@ -380,7 +388,7 @@ sa_proto_get_properties(char *proto)
sa_protocol_properties_t props = NULL;
if (ops != NULL && ops->sa_get_proto_set != NULL)
- props = ops->sa_get_proto_set();
+ props = ops->sa_get_proto_set();
return (props);
}
@@ -395,15 +403,16 @@ sa_proto_set_property(char *proto, sa_property_t prop)
{
struct sa_plugin_ops *ops = find_protocol(proto);
int ret = SA_OK;
+
if (ops != NULL && ops->sa_set_proto_prop != NULL)
- ret = ops->sa_set_proto_prop(prop);
+ ret = ops->sa_set_proto_prop(prop);
return (ret);
}
/*
* sa_valid_protocol(proto)
*
- * check to see if the protocol specified is defined by a
+ * Check to see if the protocol specified is defined by a
* plugin. Returns true (1) or false (0)
*/
@@ -424,7 +433,7 @@ sa_get_protocol_status(char *proto)
struct sa_plugin_ops *ops = find_protocol(proto);
char *ret = NULL;
if (ops != NULL && ops->sa_get_proto_status != NULL)
- ret = ops->sa_get_proto_status(proto);
+ ret = ops->sa_get_proto_status(proto);
return (ret);
}
@@ -442,8 +451,8 @@ sa_proto_update_legacy(char *proto, sa_share_t share)
int ret = SA_NOT_IMPLEMENTED;
if (ops != NULL) {
- if (ops->sa_update_legacy != NULL)
- ret = ops->sa_update_legacy(share);
+ if (ops->sa_update_legacy != NULL)
+ ret = ops->sa_update_legacy(share);
}
return (ret);
}
@@ -451,7 +460,7 @@ sa_proto_update_legacy(char *proto, sa_share_t share)
/*
* sa_delete_legacy(proto, share)
*
- * remove the specified share from the protocol specific legacy files.
+ * Remove the specified share from the protocol specific legacy files.
*/
int
@@ -461,13 +470,13 @@ sa_proto_delete_legacy(char *proto, sa_share_t share)
int ret = SA_OK;
if (ops != NULL) {
- if (ops->sa_delete_legacy != NULL)
- ret = ops->sa_delete_legacy(share);
+ if (ops->sa_delete_legacy != NULL)
+ ret = ops->sa_delete_legacy(share);
} else {
- if (proto != NULL)
- ret = SA_NOT_IMPLEMENTED;
- else
- ret = SA_INVALID_PROTOCOL;
+ if (proto != NULL)
+ ret = SA_NOT_IMPLEMENTED;
+ else
+ ret = SA_INVALID_PROTOCOL;
}
return (ret);
}