From nobody Wed May 14 21:54:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516873122384549.7150186334469; Thu, 25 Jan 2018 01:38:42 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73619780EE; Thu, 25 Jan 2018 09:38:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 392F6600D1; Thu, 25 Jan 2018 09:38:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 004A418033D9; Thu, 25 Jan 2018 09:38:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0P9cZ5T003125 for ; Thu, 25 Jan 2018 04:38:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id CA4BF50EDD; Thu, 25 Jan 2018 09:38:35 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE010600D1; Thu, 25 Jan 2018 09:38:33 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 09:38:12 +0000 Message-Id: <20180125093825.5834-2-berrange@redhat.com> In-Reply-To: <20180125093825.5834-1-berrange@redhat.com> References: <20180125093825.5834-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/14] storage: extract storage file backend from main storage driver backend X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 25 Jan 2018 09:38:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The storage driver backends are serving the public storage pools API, while the storage file backends are serving the internal QEMU driver and / or libvirt utility code. To prep for moving this storage file backend framework into the utility code, split out the backend definitions. Signed-off-by: Daniel P. Berrange --- po/POTFILES.in | 1 + src/Makefile.am | 1 + src/storage/storage_backend.c | 66 --------------------- src/storage/storage_backend.h | 75 ----------------------- src/storage/storage_backend_fs.c | 7 ++- src/storage/storage_backend_gluster.c | 3 +- src/storage/storage_source.c | 2 +- src/storage/storage_source_backend.c | 108 ++++++++++++++++++++++++++++++= ++++ src/storage/storage_source_backend.h | 104 ++++++++++++++++++++++++++++++= ++ 9 files changed, 221 insertions(+), 146 deletions(-) create mode 100644 src/storage/storage_source_backend.c create mode 100644 src/storage/storage_source_backend.h diff --git a/po/POTFILES.in b/po/POTFILES.in index c1fa23427e..7145af7176 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -187,6 +187,7 @@ src/storage/storage_backend_vstorage.c src/storage/storage_backend_zfs.c src/storage/storage_driver.c src/storage/storage_source.c +src/storage/storage_source_backend.c src/storage/storage_util.c src/test/test_driver.c src/uml/uml_conf.c diff --git a/src/Makefile.am b/src/Makefile.am index 166c9a8e91..412eb10a4a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1057,6 +1057,7 @@ STORAGE_DRIVER_BACKEND_SOURCES =3D \ STORAGE_DRIVER_SOURCES =3D \ storage/storage_driver.h storage/storage_driver.c \ storage/storage_source.h storage/storage_source.c \ + storage/storage_source_backend.h storage/storage_source_backend.c \ $(STORAGE_DRIVER_BACKEND_SOURCES) \ storage/storage_util.h storage/storage_util.c =20 diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 5a8c4f7f6a..053f4ecf26 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -78,8 +78,6 @@ VIR_LOG_INIT("storage.storage_backend"); =20 static virStorageBackendPtr virStorageBackends[VIR_STORAGE_BACKENDS_MAX]; static size_t virStorageBackendsCount; -static virStorageFileBackendPtr virStorageFileBackends[VIR_STORAGE_BACKEND= S_MAX]; -static size_t virStorageFileBackendsCount; =20 #define STORAGE_BACKEND_MODULE_DIR LIBDIR "/libvirt/storage-backend" =20 @@ -179,27 +177,6 @@ virStorageBackendRegister(virStorageBackendPtr backend) } =20 =20 -int -virStorageBackendFileRegister(virStorageFileBackendPtr backend) -{ - VIR_DEBUG("Registering storage file backend '%s' protocol '%s'", - virStorageTypeToString(backend->type), - virStorageNetProtocolTypeToString(backend->protocol)); - - if (virStorageFileBackendsCount >=3D VIR_STORAGE_BACKENDS_MAX) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Too many drivers, cannot register storage file " - "backend '%s'"), - virStorageTypeToString(backend->type)); - return -1; - } - - virStorageFileBackends[virStorageFileBackendsCount] =3D backend; - virStorageFileBackendsCount++; - return 0; -} - - virStorageBackendPtr virStorageBackendForType(int type) { @@ -213,46 +190,3 @@ virStorageBackendForType(int type) type, NULLSTR(virStoragePoolTypeToString(type))); return NULL; } - - -virStorageFileBackendPtr -virStorageFileBackendForTypeInternal(int type, - int protocol, - bool report) -{ - size_t i; - - for (i =3D 0; i < virStorageFileBackendsCount; i++) { - if (virStorageFileBackends[i]->type =3D=3D type) { - if (type =3D=3D VIR_STORAGE_TYPE_NETWORK && - virStorageFileBackends[i]->protocol !=3D protocol) - continue; - - return virStorageFileBackends[i]; - } - } - - if (!report) - return NULL; - - if (type =3D=3D VIR_STORAGE_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("missing storage backend for network files " - "using %s protocol"), - virStorageNetProtocolTypeToString(protocol)); - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("missing storage backend for '%s' storage"), - virStorageTypeToString(type)); - } - - return NULL; -} - - -virStorageFileBackendPtr -virStorageFileBackendForType(int type, - int protocol) -{ - return virStorageFileBackendForTypeInternal(type, protocol, true); -} diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index 193cf134d6..f9aa4cd26b 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -125,83 +125,8 @@ struct _virStorageBackend { =20 virStorageBackendPtr virStorageBackendForType(int type); =20 -/* ------- virStorageFile backends ------------ */ -typedef struct _virStorageFileBackend virStorageFileBackend; -typedef virStorageFileBackend *virStorageFileBackendPtr; - -struct _virStorageDriverData { - virStorageFileBackendPtr backend; - void *priv; - - uid_t uid; - gid_t gid; -}; - -typedef int -(*virStorageFileBackendInit)(virStorageSourcePtr src); - -typedef void -(*virStorageFileBackendDeinit)(virStorageSourcePtr src); - -typedef int -(*virStorageFileBackendCreate)(virStorageSourcePtr src); - -typedef int -(*virStorageFileBackendUnlink)(virStorageSourcePtr src); - -typedef int -(*virStorageFileBackendStat)(virStorageSourcePtr src, - struct stat *st); - -typedef ssize_t -(*virStorageFileBackendRead)(virStorageSourcePtr src, - size_t offset, - size_t len, - char **buf); - -typedef const char * -(*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src); - -typedef int -(*virStorageFileBackendAccess)(virStorageSourcePtr src, - int mode); - -typedef int -(*virStorageFileBackendChown)(const virStorageSource *src, - uid_t uid, - gid_t gid); - -virStorageFileBackendPtr virStorageFileBackendForType(int type, int protoc= ol); -virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type, - int protocol, - bool report); - - -struct _virStorageFileBackend { - int type; - int protocol; - - /* All storage file callbacks may be omitted if not implemented */ - - /* The following group of callbacks is expected to set a libvirt - * error on failure. */ - virStorageFileBackendInit backendInit; - virStorageFileBackendDeinit backendDeinit; - virStorageFileBackendRead storageFileRead; - virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifie= r; - - /* The following group of callbacks is expected to set errno - * and return -1 on error. No libvirt error shall be reported */ - virStorageFileBackendCreate storageFileCreate; - virStorageFileBackendUnlink storageFileUnlink; - virStorageFileBackendStat storageFileStat; - virStorageFileBackendAccess storageFileAccess; - virStorageFileBackendChown storageFileChown; -}; - int virStorageBackendDriversRegister(bool allmodules); =20 int virStorageBackendRegister(virStorageBackendPtr backend); -int virStorageBackendFileRegister(virStorageFileBackendPtr backend); =20 #endif /* __VIR_STORAGE_BACKEND_H__ */ diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index f54759983c..a1531b8493 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -37,6 +37,7 @@ =20 #include "virerror.h" #include "storage_backend_fs.h" +#include "storage_source_backend.h" #include "storage_util.h" #include "storage_conf.h" #include "virstoragefile.h" @@ -918,13 +919,13 @@ virStorageBackendFsRegister(void) return -1; #endif /* WITH_STORAGE_FS */ =20 - if (virStorageBackendFileRegister(&virStorageFileBackendFile) < 0) + if (virStorageFileBackendRegister(&virStorageFileBackendFile) < 0) return -1; =20 - if (virStorageBackendFileRegister(&virStorageFileBackendBlock) < 0) + if (virStorageFileBackendRegister(&virStorageFileBackendBlock) < 0) return -1; =20 - if (virStorageBackendFileRegister(&virStorageFileBackendDir) < 0) + if (virStorageFileBackendRegister(&virStorageFileBackendDir) < 0) return -1; =20 return 0; diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 5eea84f16e..c32267875d 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -24,6 +24,7 @@ #include =20 #include "storage_backend_gluster.h" +#include "storage_source_backend.h" #include "storage_conf.h" #include "viralloc.h" #include "virerror.h" @@ -869,7 +870,7 @@ virStorageBackendGlusterRegister(void) if (virStorageBackendRegister(&virStorageBackendGluster) < 0) return -1; =20 - if (virStorageBackendFileRegister(&virStorageFileBackendGluster) < 0) + if (virStorageFileBackendRegister(&virStorageFileBackendGluster) < 0) return -1; =20 return 0; diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c index 170ab755b7..a5eefe5032 100644 --- a/src/storage/storage_source.c +++ b/src/storage/storage_source.c @@ -26,7 +26,7 @@ =20 #include "virerror.h" #include "storage_source.h" -#include "storage_backend.h" +#include "storage_source_backend.h" #include "viralloc.h" #include "virlog.h" #include "virstring.h" diff --git a/src/storage/storage_source_backend.c b/src/storage/storage_sou= rce_backend.c new file mode 100644 index 0000000000..e093c04989 --- /dev/null +++ b/src/storage/storage_source_backend.c @@ -0,0 +1,108 @@ +/* + * storage_source_backend.c: internal storage source backend contract + * + * Copyright (C) 2007-2018 Red Hat, Inc. + * Copyright (C) 2007-2008 Daniel P. Berrange + * + * 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 + * . + * + * Author: Daniel P. Berrange + */ + +#include + +#include +#include + +#include "datatypes.h" +#include "virerror.h" +#include "viralloc.h" +#include "internal.h" +#include "storage_source_backend.h" +#include "virlog.h" +#include "virfile.h" +#include "configmake.h" + +#define VIR_FROM_THIS VIR_FROM_STORAGE + +VIR_LOG_INIT("storage.storage_source_backend"); + +#define VIR_STORAGE_BACKENDS_MAX 20 + +static virStorageFileBackendPtr virStorageFileBackends[VIR_STORAGE_BACKEND= S_MAX]; +static size_t virStorageFileBackendsCount; + + +int +virStorageFileBackendRegister(virStorageFileBackendPtr backend) +{ + VIR_DEBUG("Registering storage file backend '%s' protocol '%s'", + virStorageTypeToString(backend->type), + virStorageNetProtocolTypeToString(backend->protocol)); + + if (virStorageFileBackendsCount >=3D VIR_STORAGE_BACKENDS_MAX) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Too many drivers, cannot register storage file " + "backend '%s'"), + virStorageTypeToString(backend->type)); + return -1; + } + + virStorageFileBackends[virStorageFileBackendsCount] =3D backend; + virStorageFileBackendsCount++; + return 0; +} + +virStorageFileBackendPtr +virStorageFileBackendForTypeInternal(int type, + int protocol, + bool report) +{ + size_t i; + + for (i =3D 0; i < virStorageFileBackendsCount; i++) { + if (virStorageFileBackends[i]->type =3D=3D type) { + if (type =3D=3D VIR_STORAGE_TYPE_NETWORK && + virStorageFileBackends[i]->protocol !=3D protocol) + continue; + + return virStorageFileBackends[i]; + } + } + + if (!report) + return NULL; + + if (type =3D=3D VIR_STORAGE_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("missing storage backend for network files " + "using %s protocol"), + virStorageNetProtocolTypeToString(protocol)); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("missing storage backend for '%s' storage"), + virStorageTypeToString(type)); + } + + return NULL; +} + + +virStorageFileBackendPtr +virStorageFileBackendForType(int type, + int protocol) +{ + return virStorageFileBackendForTypeInternal(type, protocol, true); +} diff --git a/src/storage/storage_source_backend.h b/src/storage/storage_sou= rce_backend.h new file mode 100644 index 0000000000..8288bebb1f --- /dev/null +++ b/src/storage/storage_source_backend.h @@ -0,0 +1,104 @@ +/* + * storage_source_backend.h: internal storage source backend contract + * + * Copyright (C) 2007-2018 Red Hat, Inc. + * + * 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 + * . + */ + +#ifndef __VIR_STORAGE_SOURCE_BACKEND_H__ +# define __VIR_STORAGE_SOURCE_BACKEND_H__ + +# include + +# include "virstoragefile.h" + +/* ------- virStorageFile backends ------------ */ +typedef struct _virStorageFileBackend virStorageFileBackend; +typedef virStorageFileBackend *virStorageFileBackendPtr; + +struct _virStorageDriverData { + virStorageFileBackendPtr backend; + void *priv; + + uid_t uid; + gid_t gid; +}; + +typedef int +(*virStorageFileBackendInit)(virStorageSourcePtr src); + +typedef void +(*virStorageFileBackendDeinit)(virStorageSourcePtr src); + +typedef int +(*virStorageFileBackendCreate)(virStorageSourcePtr src); + +typedef int +(*virStorageFileBackendUnlink)(virStorageSourcePtr src); + +typedef int +(*virStorageFileBackendStat)(virStorageSourcePtr src, + struct stat *st); + +typedef ssize_t +(*virStorageFileBackendRead)(virStorageSourcePtr src, + size_t offset, + size_t len, + char **buf); + +typedef const char * +(*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src); + +typedef int +(*virStorageFileBackendAccess)(virStorageSourcePtr src, + int mode); + +typedef int +(*virStorageFileBackendChown)(const virStorageSource *src, + uid_t uid, + gid_t gid); + +virStorageFileBackendPtr virStorageFileBackendForType(int type, int protoc= ol); +virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type, + int protocol, + bool report); + + +struct _virStorageFileBackend { + int type; + int protocol; + + /* All storage file callbacks may be omitted if not implemented */ + + /* The following group of callbacks is expected to set a libvirt + * error on failure. */ + virStorageFileBackendInit backendInit; + virStorageFileBackendDeinit backendDeinit; + virStorageFileBackendRead storageFileRead; + virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifie= r; + + /* The following group of callbacks is expected to set errno + * and return -1 on error. No libvirt error shall be reported */ + virStorageFileBackendCreate storageFileCreate; + virStorageFileBackendUnlink storageFileUnlink; + virStorageFileBackendStat storageFileStat; + virStorageFileBackendAccess storageFileAccess; + virStorageFileBackendChown storageFileChown; +}; + +int virStorageFileBackendRegister(virStorageFileBackendPtr backend); + +#endif /* __VIR_STORAGE_BACKEND_H__ */ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list