From ac85b22014c8c230358d08e03d66bc918f969f5b Mon Sep 17 00:00:00 2001 From: armanamjad Date: Mon, 10 Apr 2023 11:10:19 -0700 Subject: [PATCH 1/3] Add custom changes for disk sas uri --- options/options.c | 6 ++++++ options/options.h | 1 + options/uri.c | 27 ++++++++++++++++++++------- options/uri.h | 1 + 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/options/options.c b/options/options.c index abdcbae..f42ca46 100644 --- a/options/options.c +++ b/options/options.c @@ -78,6 +78,7 @@ option_a (const char *arg, const char *format, int blocksize, /* Remote storage. */ drv->type = drv_uri; drv->uri.path = uri.path; + drv->uri.query = uri.query; drv->uri.protocol = uri.protocol; drv->uri.server = uri.server; drv->uri.username = uri.username; @@ -179,6 +180,11 @@ add_drives_handle (guestfs_h *g, struct drv *drv, size_t drive_index) ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_SECRET_BITMASK; ad_optargs.secret = drv->uri.password; } + if (drv->uri.query) { + ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_QUERY_BITMASK; + ad_optargs.query = drv->uri.query; + } + #ifdef GUESTFS_ADD_DRIVE_OPTS_BLOCKSIZE_BITMASK if (drv->uri.blocksize) { ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_BLOCKSIZE_BITMASK; diff --git a/options/options.h b/options/options.h index 60d5d80..dd84ba5 100644 --- a/options/options.h +++ b/options/options.h @@ -68,6 +68,7 @@ struct drv { } a; struct { char *path; /* disk path */ + char *query; /* query string */ char *protocol; /* protocol (eg. "nbd") */ char **server; /* server(s) - can be NULL */ char *username; /* username - can be NULL */ diff --git a/options/uri.c b/options/uri.c index 84d393c..2ee943b 100644 --- a/options/uri.c +++ b/options/uri.c @@ -41,7 +41,7 @@ #include "uri.h" static int is_uri (const char *arg); -static int parse (const char *arg, char **path_ret, char **protocol_ret, char ***server_ret, char **username_ret, char **password_ret); +static int parse (const char *arg, char **path_ret, char **query_ret, char **protocol_ret, char ***server_ret, char **username_ret, char **password_ret); static char *query_get (xmlURIPtr uri, const char *search_name); static int make_server (xmlURIPtr uri, const char *socket, char ***ret); @@ -49,6 +49,7 @@ int parse_uri (const char *arg, struct uri *uri_ret) { char *path = NULL; + char *query = NULL; char *protocol = NULL; char **server = NULL; char *username = NULL; @@ -56,7 +57,7 @@ parse_uri (const char *arg, struct uri *uri_ret) /* Does it look like a URI? */ if (is_uri (arg)) { - if (parse (arg, &path, &protocol, &server, &username, &password) == -1) + if (parse (arg, &path, &query, &protocol, &server, &username, &password) == -1) return -1; } else { @@ -75,6 +76,7 @@ parse_uri (const char *arg, struct uri *uri_ret) } uri_ret->path = path; + uri_ret->query = query; uri_ret->protocol = protocol; uri_ret->server = server; uri_ret->username = username; @@ -107,7 +109,7 @@ is_uri (const char *arg) } static int -parse (const char *arg, char **path_ret, char **protocol_ret, +parse (const char *arg, char **path_ret, char **query_ret, char **protocol_ret, char ***server_ret, char **username_ret, char **password_ret) { CLEANUP_XMLFREEURI xmlURIPtr uri = NULL; @@ -190,16 +192,16 @@ parse (const char *arg, char **path_ret, char **protocol_ret, * exportname expected will be "pool/disk". Here, uri->path will be * "/pool/disk" so we have to knock off the leading '/' character. */ - path = uri->path; - if (path && path[0] == '/' && + char *tmpPath = uri->path; + if (tmpPath && tmpPath[0] == '/' && (STREQ (uri->scheme, "gluster") || STREQ (uri->scheme, "iscsi") || STREQ (uri->scheme, "nbd") || STREQ (uri->scheme, "rbd") || STREQ (uri->scheme, "sheepdog"))) - path++; + tmpPath++; - *path_ret = strdup (path ? path : ""); + *path_ret = strdup (tmpPath ? tmpPath : ""); if (*path_ret == NULL) { perror ("strdup: path"); free (*protocol_ret); @@ -209,6 +211,17 @@ parse (const char *arg, char **path_ret, char **protocol_ret, return -1; } + *query_ret = strdup(uri->query_raw ? uri->query_raw : ""); + if (*query_ret == NULL) { + perror ("strdup: query"); + free (*protocol_ret); + guestfs_int_free_string_list (*server_ret); + free (*username_ret); + free (*password_ret); + free (*path_ret); + return -1; + } + return 0; } diff --git a/options/uri.h b/options/uri.h index 9202a70..d44bac2 100644 --- a/options/uri.h +++ b/options/uri.h @@ -23,6 +23,7 @@ struct uri { char *path; /* disk path */ + char *query; /* query string */ char *protocol; /* protocol (eg. "file", "nbd") */ char **server; /* server(s) - can be NULL */ char *username; /* username - can be NULL */ From a5ade5b8f9228edb67ceb721f6c9dde75d5c4dfb Mon Sep 17 00:00:00 2001 From: Arman Amjad Date: Fri, 17 Oct 2025 14:59:43 -0700 Subject: [PATCH 2/3] Rename path variable --- options/uri.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/options/uri.c b/options/uri.c index c95596f..33a8a99 100644 --- a/options/uri.c +++ b/options/uri.c @@ -195,16 +195,16 @@ parse (const char *arg, char **path_ret, char **query_ret, char **protocol_ret, * exportname expected will be "pool/disk". Here, uri->path will be * "/pool/disk" so we have to knock off the leading '/' character. */ - char *tmpPath = uri->path; - if (tmpPath && tmpPath[0] == '/' && + char *path = uri->path; + if (path && path[0] == '/' && (STREQ (uri->scheme, "gluster") || STREQ (uri->scheme, "iscsi") || STRPREFIX (uri->scheme, "nbd") || STREQ (uri->scheme, "rbd") || STREQ (uri->scheme, "sheepdog"))) - tmpPath++; + path++; - *path_ret = strdup (tmpPath ? tmpPath : ""); + *path_ret = strdup (path ? path : ""); if (*path_ret == NULL) { perror ("strdup: path"); free (*protocol_ret); From 786839447e10a7f83ea51dd46fcf33ef79ea48f7 Mon Sep 17 00:00:00 2001 From: Arman Amjad Date: Fri, 17 Oct 2025 15:05:37 -0700 Subject: [PATCH 3/3] Remove unnecessary initializer --- options/uri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/uri.c b/options/uri.c index 33a8a99..00be626 100644 --- a/options/uri.c +++ b/options/uri.c @@ -195,7 +195,7 @@ parse (const char *arg, char **path_ret, char **query_ret, char **protocol_ret, * exportname expected will be "pool/disk". Here, uri->path will be * "/pool/disk" so we have to knock off the leading '/' character. */ - char *path = uri->path; + path = uri->path; if (path && path[0] == '/' && (STREQ (uri->scheme, "gluster") || STREQ (uri->scheme, "iscsi") ||