From e6545c2acc9a3626572cbf937c1d7eba62362e3b Mon Sep 17 00:00:00 2001 Message-Id: From: John Ferlan Date: Wed, 3 Apr 2019 09:12:18 -0400 Subject: [PATCH] storage: Rework virStorageBackendFileSystemMountCmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://bugzilla.redhat.com/show_bug.cgi?id=1584663 Let's create helpers for each style of command line created. This primarily is easier on the eyes rather than the large multi line if-then-else-else clause used, but may also be useful if in the future any particular pool needs to add to the command line based on pool xml format. Signed-off-by: John Ferlan ACKed-by: Michal Privoznik (cherry picked from commit b663d4329ca844b1bdb536acaa2ae338bf435f74) Message-Id: <20190403131219.16385-7-jferlan@redhat.com> Reviewed-by: Ján Tomko --- src/storage/storage_util.c | 84 +++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index ccbc2c925c..70ce600581 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -4245,6 +4245,56 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) } +static void +virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, + const char *src, + virStoragePoolDefPtr def) +{ + virCommandAddArgList(cmd, src, def->target.path, NULL); +} + + +static void +virStorageBackendFileSystemMountGlusterArgs(virCommandPtr cmd, + const char *src, + virStoragePoolDefPtr def) +{ + const char *fmt; + + fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); + virCommandAddArgList(cmd, "-t", fmt, src, "-o", "direct-io-mode=1", + def->target.path, NULL); +} + + +static void +virStorageBackendFileSystemMountCIFSArgs(virCommandPtr cmd, + const char *src, + virStoragePoolDefPtr def) +{ + const char *fmt; + + fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); + virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, + "-o", "guest", NULL); +} + + +static void +virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd, + const char *src, + virStoragePoolDefPtr def) +{ + const char *fmt; + + if (def->type == VIR_STORAGE_POOL_FS) + fmt = virStoragePoolFormatFileSystemTypeToString(def->source.format); + else + fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); + virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); +} + + virCommandPtr virStorageBackendFileSystemMountCmd(virStoragePoolDefPtr def, const char *src) @@ -4260,38 +4310,14 @@ virStorageBackendFileSystemMountCmd(virStoragePoolDefPtr def, def->source.format == VIR_STORAGE_POOL_NETFS_CIFS); virCommandPtr cmd = NULL; + cmd = virCommandNew(MOUNT); if (netauto) - cmd = virCommandNewArgList(MOUNT, - src, - def->target.path, - NULL); + virStorageBackendFileSystemMountNFSArgs(cmd, src, def); else if (glusterfs) - cmd = virCommandNewArgList(MOUNT, - "-t", - virStoragePoolFormatFileSystemNetTypeToString(def->source.format), - src, - "-o", - "direct-io-mode=1", - def->target.path, - NULL); + virStorageBackendFileSystemMountGlusterArgs(cmd, src, def); else if (cifsfs) - cmd = virCommandNewArgList(MOUNT, - "-t", - virStoragePoolFormatFileSystemNetTypeToString(def->source.format), - src, - def->target.path, - "-o", - "guest", - NULL); + virStorageBackendFileSystemMountCIFSArgs(cmd, src, def); else - cmd = virCommandNewArgList(MOUNT, - "-t", - (def->type == VIR_STORAGE_POOL_FS ? - virStoragePoolFormatFileSystemTypeToString(def->source.format) : - virStoragePoolFormatFileSystemNetTypeToString(def->source.format)), - src, - def->target.path, - NULL); - + virStorageBackendFileSystemMountDefaultArgs(cmd, src, def); return cmd; } -- 2.21.0