@@ -114,6 +114,7 @@ fedfs_create_junction_call(const char *hostname, const char *nettype,
enum clnt_stat status;
FedFsCreateArgs arg;
FedFsStatus result;
+ char **path_array;
CLIENT *client;
uuid_t uu;
int res;
@@ -132,11 +133,18 @@ fedfs_create_junction_call(const char *hostname, const char *nettype,
arg.fsn.nsdbName.port = nsdbport;
arg.path.type = FEDFS_PATH_SYS;
- result = nsdb_posix_to_fedfspathname(path,
+ result = nsdb_posix_to_path_array(path, &path_array);
+ if (result != FEDFS_OK) {
+ fprintf(stderr, "Failed to encode pathname: %s",
+ nsdb_display_fedfsstatus(result));
+ return result;
+ }
+ result = nsdb_path_array_to_fedfspathname(path_array,
&arg.path.FedFsPath_u.adminPath);
if (result != FEDFS_OK) {
fprintf(stderr, "Failed to encode pathname: %s",
nsdb_display_fedfsstatus(result));
+ nsdb_free_string_array(path_array);
return result;
}
@@ -162,6 +170,7 @@ fedfs_create_junction_call(const char *hostname, const char *nettype,
out:
nsdb_free_fedfspathname(&arg.path.FedFsPath_u.adminPath);
+ nsdb_free_string_array(path_array);
return result;
}
@@ -95,6 +95,7 @@ fedfs_create_replication_call(const char *hostname, const char *nettype,
FedFsCreateArgs arg;
enum clnt_stat status;
FedFsStatus result;
+ char **path_array;
CLIENT *client;
uuid_t uu;
int res;
@@ -113,11 +114,18 @@ fedfs_create_replication_call(const char *hostname, const char *nettype,
arg.fsn.nsdbName.port = nsdbport;
arg.path.type = FEDFS_PATH_SYS;
- result = nsdb_posix_to_fedfspathname(path,
+ result = nsdb_posix_to_path_array(path, &path_array);
+ if (result != FEDFS_OK) {
+ fprintf(stderr, "Failed to encode pathname: %s",
+ nsdb_display_fedfsstatus(result));
+ return result;
+ }
+ result = nsdb_path_array_to_fedfspathname(path_array,
&arg.path.FedFsPath_u.adminPath);
if (result != FEDFS_OK) {
fprintf(stderr, "Failed to encode pathname: %s",
nsdb_display_fedfsstatus(result));
+ nsdb_free_string_array(path_array);
return result;
}
@@ -143,6 +151,7 @@ fedfs_create_replication_call(const char *hostname, const char *nettype,
out:
nsdb_free_fedfspathname(&arg.path.FedFsPath_u.adminPath);
+ nsdb_free_string_array(path_array);
return result;
}
@@ -86,16 +86,24 @@ fedfs_delete_junction_call(const char *hostname, const char *nettype,
{
enum clnt_stat status;
FedFsStatus result;
+ char **path_array;
CLIENT *client;
FedFsPath arg;
memset(&arg, 0, sizeof(arg));
- result = nsdb_posix_to_fedfspathname(path,
+ result = nsdb_posix_to_path_array(path, &path_array);
+ if (result != FEDFS_OK) {
+ fprintf(stderr, "Failed to encode pathname: %s",
+ nsdb_display_fedfsstatus(result));
+ return result;
+ }
+ result = nsdb_path_array_to_fedfspathname(path_array,
&arg.FedFsPath_u.adminPath);
if (result != FEDFS_OK) {
fprintf(stderr, "Failed to encode pathname: %s",
nsdb_display_fedfsstatus(result));
+ nsdb_free_string_array(path_array);
return result;
}
@@ -120,6 +128,7 @@ fedfs_delete_junction_call(const char *hostname, const char *nettype,
out:
nsdb_free_fedfspathname(&arg.FedFsPath_u.adminPath);
+ nsdb_free_string_array(path_array);
return result;
}
@@ -86,16 +86,24 @@ fedfs_delete_replication_call(const char *hostname, const char *nettype,
{
enum clnt_stat status;
FedFsStatus result;
+ char **path_array;
CLIENT *client;
FedFsPath arg;
memset(&arg, 0, sizeof(arg));
- result = nsdb_posix_to_fedfspathname(path,
+ result = nsdb_posix_to_path_array(path, &path_array);
+ if (result != FEDFS_OK) {
+ fprintf(stderr, "Failed to encode pathname: %s",
+ nsdb_display_fedfsstatus(result));
+ return result;
+ }
+ result = nsdb_path_array_to_fedfspathname(path_array,
&arg.FedFsPath_u.adminPath);
if (result != FEDFS_OK) {
fprintf(stderr, "Failed to encode pathname: %s",
nsdb_display_fedfsstatus(result));
+ nsdb_free_string_array(path_array);
return result;
}
@@ -120,6 +128,7 @@ fedfs_delete_replication_call(const char *hostname, const char *nettype,
out:
nsdb_free_fedfspathname(&arg.FedFsPath_u.adminPath);
+ nsdb_free_string_array(path_array);
return result;
}
@@ -144,7 +144,8 @@ static void
fedfs_lookup_junction_print_nfs_fsl(FedFsNfsFsl fsl)
{
FedFsStatus status;
- char *pathname;
+ char **path_array;
+ unsigned int i;
fedfs_lookup_junction_print_uuid(" FSL UUID", fsl.fslUuid);
if (fsl.hostname.utf8string_val == NULL)
@@ -154,13 +155,21 @@ fedfs_lookup_junction_print_nfs_fsl(FedFsNfsFsl fsl)
fsl.hostname.utf8string_len,
fsl.hostname.utf8string_val,
fsl.port);
- status = nsdb_fedfspathname_to_posix(fsl.path, &pathname);
+ status = nsdb_fedfspathname_to_path_array(fsl.path, &path_array);
if (status != FEDFS_OK)
printf(" Returned NFS export pathname was invalid: %s\n",
nsdb_display_fedfsstatus(status));
else {
- printf(" FSL NFS pathname: %s\n", pathname);
- free(pathname);
+ if (path_array[0] == NULL)
+ printf(" FSL NFS pathname: /\n");
+ else {
+ printf(" FSL NFS pathname: ");
+ for (i = 0; path_array[i] != NULL; i++)
+ printf("/%s", path_array[i]);
+ printf("\n");
+ }
+
+ nsdb_free_string_array(path_array);
}
}
@@ -216,8 +225,9 @@ fedfs_lookup_junction_call(const char *hostname, const char *nettype,
const char *path, const char *resolvetype)
{
FedFsLookupRes result;
- FedFsLookupArgs arg;
enum clnt_stat status;
+ FedFsLookupArgs arg;
+ char **path_array;
CLIENT *client;
memset(&arg, 0, sizeof(arg));
@@ -225,11 +235,18 @@ fedfs_lookup_junction_call(const char *hostname, const char *nettype,
if (!fedfs_lookup_junction_get_resolvetype(resolvetype, &arg.resolve))
return FEDFS_ERR_INVAL;
arg.path.type = FEDFS_PATH_SYS;
- result.status = nsdb_posix_to_fedfspathname(path,
+ result.status = nsdb_posix_to_path_array(path, &path_array);
+ if (result.status != FEDFS_OK) {
+ fprintf(stderr, "Failed to encode pathname: %s",
+ nsdb_display_fedfsstatus(result.status));
+ return result.status;
+ }
+ result.status = nsdb_path_array_to_fedfspathname(path_array,
&arg.path.FedFsPath_u.adminPath);
if (result.status != FEDFS_OK) {
fprintf(stderr, "Failed to encode pathname: %s",
nsdb_display_fedfsstatus(result.status));
+ nsdb_free_string_array(path_array);
return result.status;
}
@@ -258,6 +275,7 @@ fedfs_lookup_junction_call(const char *hostname, const char *nettype,
out:
nsdb_free_fedfspathname(&arg.path.FedFsPath_u.adminPath);
+ nsdb_free_string_array(path_array);
exit(result.status);
}
@@ -144,7 +144,8 @@ static void
fedfs_lookup_replication_print_nfs_fsl(FedFsNfsFsl fsl)
{
FedFsStatus status;
- char *pathname;
+ char **path_array;
+ unsigned int i;
fedfs_lookup_replication_print_uuid("Fsl UUID", fsl.fslUuid);
if (fsl.hostname.utf8string_val == NULL)
@@ -154,13 +155,21 @@ fedfs_lookup_replication_print_nfs_fsl(FedFsNfsFsl fsl)
fsl.hostname.utf8string_len,
fsl.hostname.utf8string_val,
fsl.port);
- status = nsdb_fedfspathname_to_posix(fsl.path, &pathname);
+ status = nsdb_fedfspathname_to_path_array(fsl.path, &path_array);
if (status != FEDFS_OK)
printf("Returned NFS export pathname was invalid: %s\n",
nsdb_display_fedfsstatus(status));
else {
- printf("FSL NFS pathname: %s\n", pathname);
- free(pathname);
+ if (path_array[0] == NULL)
+ printf(" FSL NFS pathname: /\n");
+ else {
+ printf(" FSL NFS pathname: ");
+ for (i = 0; path_array[i] != NULL; i++)
+ printf("/%s", path_array[i]);
+ printf("\n");
+ }
+
+ nsdb_free_string_array(path_array);
}
}
@@ -221,8 +230,9 @@ fedfs_lookup_replication_call(const char *hostname, const char *nettype,
const char *path, const char *resolvetype)
{
FedFsLookupRes result;
- FedFsLookupArgs arg;
enum clnt_stat status;
+ FedFsLookupArgs arg;
+ char **path_array;
CLIENT *client;
memset(&arg, 0, sizeof(arg));
@@ -230,11 +240,18 @@ fedfs_lookup_replication_call(const char *hostname, const char *nettype,
if (!fedfs_lookup_replication_get_resolvetype(resolvetype, &arg.resolve))
return FEDFS_ERR_INVAL;
arg.path.type = FEDFS_PATH_SYS;
- result.status = nsdb_posix_to_fedfspathname(path,
+ result.status = nsdb_posix_to_path_array(path, &path_array);
+ if (result.status != FEDFS_OK) {
+ fprintf(stderr, "Failed to encode pathname: %s",
+ nsdb_display_fedfsstatus(result.status));
+ return result.status;
+ }
+ result.status = nsdb_path_array_to_fedfspathname(path_array,
&arg.path.FedFsPath_u.adminPath);
if (result.status != FEDFS_OK) {
fprintf(stderr, "Failed to encode pathname: %s",
nsdb_display_fedfsstatus(result.status));
+ nsdb_free_string_array(path_array);
return result.status;
}
@@ -263,6 +280,7 @@ fedfs_lookup_replication_call(const char *hostname, const char *nettype,
out:
nsdb_free_fedfspathname(&arg.path.FedFsPath_u.adminPath);
+ nsdb_free_string_array(path_array);
return result.status;
}
Since the beginning, I've tried to stick with representing local pathnames using a C string, and converting to the array form only when I need to transmit the pathname off-system. That seemed more natural for operating on Linux, whose VFS is POSIX-style. I've introduced a new pathname API based on arrays of components. Convert the FedFS ADMIN clients to use this new API when dealing with input pathnames. This change moves an important part of pathname resolution policy out of libnsdb and into callers. It should also provide an opportunity for stronger and more consistent checks on incoming pathnames. There shouldn't be any change in behavior with this patch. Someday, though, we may want to expand the command line interface of these clients (or, build new clients) that allow more precise specification of the pathname arguments. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> --- src/fedfsc/fedfs-create-junction.c | 11 ++++++++++- src/fedfsc/fedfs-create-replication.c | 11 ++++++++++- src/fedfsc/fedfs-delete-junction.c | 11 ++++++++++- src/fedfsc/fedfs-delete-replication.c | 11 ++++++++++- src/fedfsc/fedfs-lookup-junction.c | 30 ++++++++++++++++++++++++------ src/fedfsc/fedfs-lookup-replication.c | 30 ++++++++++++++++++++++++------ 6 files changed, 88 insertions(+), 16 deletions(-)