[libvirt] [PATCH RFC v3 01/15] storage pools: refactoring of basic structs

Olga Krishtal okrishtal at virtuozzo.com
Fri Dec 2 15:38:06 UTC 2016


This is the first patch in fspool patchest.
FSPool and storage pools has a lot in common, however we
want to have separate drivers for its managment.

We want to use almost all storage pool descriptional structures
for filesystem pool. All common structs is moved to
virpoolcommon.h

Signed-off-by: Olga Krishtal <okrishtal at virtuozzo.com>
---
 include/libvirt/libvirt-storage.h |   5 +-
 src/Makefile.am                   |   5 +-
 src/conf/storage_conf.h           | 126 +++--------------------------
 src/datatypes.h                   |   4 +-
 src/util/virpoolcommon.h          | 166 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 184 insertions(+), 122 deletions(-)
 create mode 100644 src/util/virpoolcommon.h

diff --git a/include/libvirt/libvirt-storage.h b/include/libvirt/libvirt-storage.h
index 0974f6e..8572685 100644
--- a/include/libvirt/libvirt-storage.h
+++ b/include/libvirt/libvirt-storage.h
@@ -34,7 +34,7 @@
  *
  * a virStoragePool is a private structure representing a storage pool
  */
-typedef struct _virStoragePool virStoragePool;
+typedef struct _virPoolCommon virStoragePool;
 
 /**
  * virStoragePoolPtr:
@@ -44,7 +44,6 @@ typedef struct _virStoragePool virStoragePool;
  */
 typedef virStoragePool *virStoragePoolPtr;
 
-
 typedef enum {
     VIR_STORAGE_POOL_INACTIVE = 0, /* Not running */
     VIR_STORAGE_POOL_BUILDING = 1, /* Initializing pool, not available */
@@ -104,7 +103,7 @@ typedef virStoragePoolInfo *virStoragePoolInfoPtr;
  *
  * a virStorageVol is a private structure representing a storage volume
  */
-typedef struct _virStorageVol virStorageVol;
+typedef struct _virItemCommon virStorageVol;
 
 /**
  * virStorageVolPtr:
diff --git a/src/Makefile.am b/src/Makefile.am
index 8ee5567..f8d4a5b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -170,7 +170,7 @@ UTIL_SOURCES =							\
 		util/virstats.c util/virstats.h	\
 		util/virstorageencryption.c util/virstorageencryption.h \
 		util/virstoragefile.c util/virstoragefile.h	\
-		util/virstring.h util/virstring.c		\
+        util/virstring.h util/virstring.c		\
 		util/virsysinfo.c util/virsysinfo.h		\
 		util/virsystemd.c util/virsystemd.h		\
 		util/virthread.c util/virthread.h		\
@@ -185,7 +185,8 @@ UTIL_SOURCES =							\
 		util/viruuid.c util/viruuid.h			\
 		util/virxdrdefs.h                               \
 		util/virxml.c util/virxml.h			\
-		$(NULL)
+		util/virpoolcommon.h                \
+        $(NULL)
 
 EXTRA_DIST += $(srcdir)/util/keymaps.csv $(srcdir)/util/virkeycode-mapgen.py
 
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 185ae5e..8a9a789 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -27,6 +27,7 @@
 # include "internal.h"
 # include "virstorageencryption.h"
 # include "virstoragefile.h"
+# include "virpoolcommon.h"
 # include "virbitmap.h"
 # include "virthread.h"
 # include "device_conf.h"
@@ -58,7 +59,6 @@ struct _virStorageVolSource {
                    * backend for partition type creation */
 };
 
-
 typedef struct _virStorageVolDef virStorageVolDef;
 typedef virStorageVolDef *virStorageVolDefPtr;
 struct _virStorageVolDef {
@@ -73,6 +73,7 @@ struct _virStorageVolDef {
     virStorageSource target;
 };
 
+
 typedef struct _virStorageVolDefList virStorageVolDefList;
 typedef virStorageVolDefList *virStorageVolDefListPtr;
 struct _virStorageVolDefList {
@@ -112,12 +113,8 @@ typedef enum {
 /*
  * For remote pools, info on how to reach the host
  */
-typedef struct _virStoragePoolSourceHost virStoragePoolSourceHost;
+typedef virPoolSourceHost virStoragePoolSourceHost;
 typedef virStoragePoolSourceHost *virStoragePoolSourceHostPtr;
-struct _virStoragePoolSourceHost {
-    char *name;
-    int port;
-};
 
 
 /*
@@ -142,127 +139,27 @@ struct _virStoragePoolSourceDeviceExtent {
     int type; /* virStorageFreeType */
 };
 
-typedef struct _virStoragePoolSourceInitiatorAttr virStoragePoolSourceInitiatorAttr;
-struct _virStoragePoolSourceInitiatorAttr {
-    char *iqn; /* Initiator IQN */
-};
-
 /*
  * Pools can be backed by one or more devices, and some
  * allow us to track free space on underlying devices.
  */
-typedef struct _virStoragePoolSourceDevice virStoragePoolSourceDevice;
+typedef virPoolSourceDevice virStoragePoolSourceDevice;
 typedef virStoragePoolSourceDevice *virStoragePoolSourceDevicePtr;
-struct _virStoragePoolSourceDevice {
-    int nfreeExtent;
-    virStoragePoolSourceDeviceExtentPtr freeExtents;
-    char *path;
-    int format; /* Pool specific source format */
-    int part_separator;  /* enum virTristateSwitch */
-
-    /* When the source device is a physical disk,
-     * the geometry data is needed
-     */
-    struct _geometry {
-        int cylinders;
-        int heads;
-        int sectors;
-    } geometry;
-};
 
-typedef enum {
-    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_DEFAULT = 0,
-    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST,
-    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST,
-
-    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_LAST,
-} virStoragePoolSourceAdapterType;
-VIR_ENUM_DECL(virStoragePoolSourceAdapter)
-
-typedef struct _virStoragePoolSourceAdapter virStoragePoolSourceAdapter;
+typedef virPoolSourceAdapter virStoragePoolSourceAdapter;
 typedef virStoragePoolSourceAdapter *virStoragePoolSourceAdapterPtr;
-struct _virStoragePoolSourceAdapter {
-    int type; /* virStoragePoolSourceAdapterType */
-
-    union {
-        struct {
-            char *name;
-            virPCIDeviceAddress parentaddr; /* host address */
-            int unique_id;
-            bool has_parent;
-        } scsi_host;
-        struct {
-            char *parent;
-            char *wwnn;
-            char *wwpn;
-            int managed;        /* enum virTristateSwitch */
-        } fchost;
-    } data;
-};
 
-typedef struct _virStoragePoolSource virStoragePoolSource;
+typedef virPoolSource virStoragePoolSource;
 typedef virStoragePoolSource *virStoragePoolSourcePtr;
-struct _virStoragePoolSource {
-    /* An optional (maybe multiple) host(s) */
-    size_t nhost;
-    virStoragePoolSourceHostPtr hosts;
-
-    /* And either one or more devices ... */
-    size_t ndevice;
-    virStoragePoolSourceDevicePtr devices;
-
-    /* Or a directory */
-    char *dir;
-
-    /* Or an adapter */
-    virStoragePoolSourceAdapter adapter;
 
-    /* Or a name */
-    char *name;
-
-    /* Initiator IQN */
-    virStoragePoolSourceInitiatorAttr initiator;
-
-    /* Authentication information */
-    virStorageAuthDefPtr auth;
-
-    /* Vendor of the source */
-    char *vendor;
-
-    /* Product name of the source*/
-    char *product;
-
-    /* Pool type specific format such as filesystem type,
-     * or lvm version, etc.
-     */
-    int format;
-};
-
-typedef struct _virStoragePoolTarget virStoragePoolTarget;
+typedef virPoolTarget virStoragePoolTarget;
 typedef virStoragePoolTarget *virStoragePoolTargetPtr;
-struct _virStoragePoolTarget {
-    char *path; /* Optional local filesystem mapping */
-    virStoragePerms perms; /* Default permissions for volumes */
-};
 
-typedef struct _virStoragePoolDef virStoragePoolDef;
+typedef virPoolDef virStoragePoolDef;
 typedef virStoragePoolDef *virStoragePoolDefPtr;
-struct _virStoragePoolDef {
-    char *name;
-    unsigned char uuid[VIR_UUID_BUFLEN];
-    int type; /* virStoragePoolType */
-
-    unsigned long long allocation; /* bytes */
-    unsigned long long capacity; /* bytes */
-    unsigned long long available; /* bytes */
-
-    virStoragePoolSource source;
-    virStoragePoolTarget target;
-};
 
 typedef struct _virStoragePoolObj virStoragePoolObj;
 typedef virStoragePoolObj *virStoragePoolObjPtr;
-
 struct _virStoragePoolObj {
     virMutex lock;
 
@@ -272,9 +169,8 @@ struct _virStoragePoolObj {
     int autostart;
     unsigned int asyncjobs;
 
-    virStoragePoolDefPtr def;
-    virStoragePoolDefPtr newDef;
-
+    virPoolDefPtr def;
+    virPoolDefPtr newDef;
     virStorageVolDefList volumes;
 };
 
@@ -307,7 +203,7 @@ typedef virStoragePoolSourceList *virStoragePoolSourceListPtr;
 struct _virStoragePoolSourceList {
     int type;
     unsigned int nsources;
-    virStoragePoolSourcePtr sources;
+    virPoolSourcePtr sources;
 };
 
 typedef bool (*virStoragePoolObjListFilter)(virConnectPtr conn,
diff --git a/src/datatypes.h b/src/datatypes.h
index 2b6adb4..1eaf4c6 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -561,7 +561,7 @@ struct _virInterface {
 *
 * Internal structure associated to a storage pool
 */
-struct _virStoragePool {
+struct _virPoolCommon {
     virObject object;
     virConnectPtr conn;                  /* pointer back to the connection */
     char *name;                          /* the storage pool external name */
@@ -580,7 +580,7 @@ struct _virStoragePool {
 *
 * Internal structure associated to a storage volume
 */
-struct _virStorageVol {
+struct _virItemCommon {
     virObject object;
     virConnectPtr conn;                  /* pointer back to the connection */
     char *pool;                          /* Pool name of owner */
diff --git a/src/util/virpoolcommon.h b/src/util/virpoolcommon.h
new file mode 100644
index 0000000..d54de36
--- /dev/null
+++ b/src/util/virpoolcommon.h
@@ -0,0 +1,166 @@
+/*
+ * virpoolcommon.h: utility to operate common parts in storage pools and
+ * filesystem pools
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIR_POOL_COMMON_H__
+# define __VIR_POOL_COMMON_H__
+
+# include "virstoragefile.h"
+# include "virthread.h"
+# include "virpci.h"
+
+/*
+ * For remote pools, info on how to reach the host
+ */
+typedef struct _virPoolSourceHost virPoolSourceHost;
+typedef virPoolSourceHost *virPoolSourceHostPtr;
+struct _virPoolSourceHost {
+    char *name;
+    int port;
+};
+
+/*
+ * Available extents on the underlying storage
+ */
+typedef struct _virPoolSourceDeviceExtent virPoolSourceDeviceExtent;
+typedef virPoolSourceDeviceExtent *virPoolSourceDeviceExtentPtr;
+struct _virPoolSourceDeviceExtent {
+    unsigned long long start;
+    unsigned long long end;
+    int type; /* virStorageFreeType */
+};
+
+/*
+ * Pools can be backed by one or more devices, and some
+ * allow us to track free space on underlying devices.
+ */
+typedef struct _virPoolSourceDevice virPoolSourceDevice;
+typedef virPoolSourceDevice *virPoolSourceDevicePtr;
+struct _virPoolSourceDevice {
+    int nfreeExtent;
+    virPoolSourceDeviceExtentPtr freeExtents;
+    char *path;
+    int format; /* Pool specific source format */
+    int part_separator;  /* enum virTristateSwitch */
+
+    /* When the source device is a physical disk,
+     * the geometry data is needed
+     */
+    struct _geometry {
+        int cylinders;
+        int heads;
+        int sectors;
+    } geometry;
+};
+
+typedef enum {
+    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_DEFAULT = 0,
+    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST,
+    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST,
+
+    VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_LAST,
+} virStoragePoolSourceAdapterType;
+VIR_ENUM_DECL(virStoragePoolSourceAdapter)
+
+typedef struct _virPoolSourceAdapter virPoolSourceAdapter;
+typedef virPoolSourceAdapter *virPoolSourceAdapterPtr;
+struct _virPoolSourceAdapter {
+    int type; /* virStoragePoolSourceAdapterType */
+
+    union {
+        struct {
+            char *name;
+            virPCIDeviceAddress parentaddr; /* host address */
+            int unique_id;
+            bool has_parent;
+        } scsi_host;
+        struct {
+            char *parent;
+            char *wwnn;
+            char *wwpn;
+            int managed;        /* enum virTristateSwitch */
+        } fchost;
+    } data;
+};
+
+typedef struct _virPoolSourceInitiatorAttr virPoolSourceInitiatorAttr;
+struct _virPoolSourceInitiatorAttr {
+    char *iqn; /* Initiator IQN */
+};
+
+typedef struct _virPoolSource virPoolSource;
+typedef virPoolSource *virPoolSourcePtr;
+struct _virPoolSource {
+    /* An optional (maybe multiple) host(s) */
+    size_t nhost;
+    virPoolSourceHostPtr hosts;
+
+    /* And either one or more devices ... */
+    size_t ndevice;
+    virPoolSourceDevicePtr devices;
+
+    /* Or a directory */
+    char *dir;
+
+    /* Or an adapter */
+    virPoolSourceAdapter adapter;
+
+    /* Or a name */
+    char *name;
+
+    /* Initiator IQN */
+    virPoolSourceInitiatorAttr initiator;
+
+    /* Authentication information */
+    virStorageAuthDefPtr auth;
+
+    /* Vendor of the source */
+    char *vendor;
+
+    /* Product name of the source*/
+    char *product;
+
+    /* Pool type specific format such as filesystem type,
+     * or lvm version, etc.
+     */
+    int format;
+};
+
+typedef struct _virPoolTarget virPoolTarget;
+typedef virPoolTarget *virPoolTargetPtr;
+struct _virPoolTarget {
+    char *path; /* Optional local filesystem mapping */
+    virStoragePerms perms; /* Default permissions for volumes/items */
+};
+
+typedef struct _virPoolDef virPoolDef;
+typedef virPoolDef *virPoolDefPtr;
+struct _virPoolDef {
+    char *name;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    int type; /* virStoragePoolType */
+
+    unsigned long long allocation; /* bytes */
+    unsigned long long capacity; /* bytes */
+    unsigned long long available; /* bytes */
+
+    virPoolSource source;
+    virPoolTarget target;
+};
+# endif /* __VIR_POOL_COMMON_H__ */
-- 
1.8.3.1




More information about the libvir-list mailing list