提交 30783d36 编写于 作者: S Sukrit Bhatnagar 提交者: Erik Skultety

util: scsi: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in
src/util/viralloc.h, define a new wrapper around an existing
cleanup function which will be called when a variable declared
with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant
viralloc.h include, since that has moved from the source module into
the header.

When variables of type virSCSIDevicePtr and virUsedByInfoPtr
are declared using VIR_AUTOPTR, the functions virSCSIDeviceFree
and virSCSIDeviceUsedByInfoFree, respectively, will be run
automatically on them when they go out of scope.

This commit also adds an intermediate typedef for virUsedByInfo
type for use with the cleanup macros.
Signed-off-by: NSukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 da5d031b
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "virlog.h" #include "virlog.h"
#include "virscsi.h" #include "virscsi.h"
#include "viralloc.h"
#include "virfile.h" #include "virfile.h"
#include "virutil.h" #include "virutil.h"
#include "virstring.h" #include "virstring.h"
...@@ -54,7 +53,8 @@ struct _virUsedByInfo { ...@@ -54,7 +53,8 @@ struct _virUsedByInfo {
char *drvname; /* which driver */ char *drvname; /* which driver */
char *domname; /* which domain */ char *domname; /* which domain */
}; };
typedef struct _virUsedByInfo *virUsedByInfoPtr; typedef struct _virUsedByInfo virUsedByInfo;
typedef virUsedByInfo *virUsedByInfoPtr;
struct _virSCSIDevice { struct _virSCSIDevice {
unsigned int adapter; unsigned int adapter;
...@@ -264,6 +264,7 @@ virSCSIDeviceUsedByInfoFree(virUsedByInfoPtr used_by) ...@@ -264,6 +264,7 @@ virSCSIDeviceUsedByInfoFree(virUsedByInfoPtr used_by)
VIR_FREE(used_by->domname); VIR_FREE(used_by->domname);
VIR_FREE(used_by); VIR_FREE(used_by);
} }
VIR_DEFINE_AUTOPTR_FUNC(virUsedByInfo, virSCSIDeviceUsedByInfoFree)
void void
virSCSIDeviceFree(virSCSIDevicePtr dev) virSCSIDeviceFree(virSCSIDevicePtr dev)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# include "internal.h" # include "internal.h"
# include "virobject.h" # include "virobject.h"
# include "viralloc.h"
typedef struct _virSCSIDevice virSCSIDevice; typedef struct _virSCSIDevice virSCSIDevice;
typedef virSCSIDevice *virSCSIDevicePtr; typedef virSCSIDevice *virSCSIDevicePtr;
...@@ -95,4 +96,6 @@ void virSCSIDeviceListDel(virSCSIDeviceListPtr list, ...@@ -95,4 +96,6 @@ void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list, virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev); virSCSIDevicePtr dev);
VIR_DEFINE_AUTOPTR_FUNC(virSCSIDevice, virSCSIDeviceFree)
#endif /* __VIR_SCSI_H__ */ #endif /* __VIR_SCSI_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册