Re: [libvirt] [PATCHv2 6/8] Move functions using iscsiadm to viriscsi.c

2014-03-20 Thread Daniel P. Berrange
On Wed, Mar 19, 2014 at 04:35:31PM +, Daniel P. Berrange wrote:
 On Wed, Mar 19, 2014 at 04:52:31PM +0100, Ján Tomko wrote:
  diff --git a/src/util/viriscsi.h b/src/util/viriscsi.h
  new file mode 100644
  index 000..462e56a
  --- /dev/null
  +++ b/src/util/viriscsi.h
  @@ -0,0 +1,52 @@
  +#ifndef __VIR_ISCSI_H__
  +# define __VIR_ISCSI_H__
  +
  +# include internal.h
  +
  +char *
  +virISCSIGetSession(const char *devpath,
  +   bool probe);
 
 Could add ATTRIBUTE_NONNULL for this 'const char *' and all
 the other pointers below
 
  +
  +int
  +virISCSIConnectionLogin(const char *portal,
  +const char *initiatoriqn,
  +const char *target);
  +int
  +virISCSIConnectionLogout(const char *portal,
  + const char *initiatoriqn,
  + const char *target);
  +int
  +virISCSIRescanLUNs(const char *session);
  +
  +int
  +virISCSIScanTargets(const char *portal,
  +const char *initiatoriqn,
  +size_t *ntargetsret,
  +char ***targetsret);
  +int
  +virISCSINodeUpdate(const char *portal,
  +   const char *target,
  +   const char *name,
  +   const char *value);
 
 And these 5 could have ATTRIBUTE_RETURN_CHECK too

Btw, I meant to say ACK - you can add the attribute annotations without
reposting this series.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCHv2 6/8] Move functions using iscsiadm to viriscsi.c

2014-03-19 Thread Daniel P. Berrange
On Wed, Mar 19, 2014 at 04:52:31PM +0100, Ján Tomko wrote:
 diff --git a/src/util/viriscsi.h b/src/util/viriscsi.h
 new file mode 100644
 index 000..462e56a
 --- /dev/null
 +++ b/src/util/viriscsi.h
 @@ -0,0 +1,52 @@
 +#ifndef __VIR_ISCSI_H__
 +# define __VIR_ISCSI_H__
 +
 +# include internal.h
 +
 +char *
 +virISCSIGetSession(const char *devpath,
 +   bool probe);

Could add ATTRIBUTE_NONNULL for this 'const char *' and all
the other pointers below

 +
 +int
 +virISCSIConnectionLogin(const char *portal,
 +const char *initiatoriqn,
 +const char *target);
 +int
 +virISCSIConnectionLogout(const char *portal,
 + const char *initiatoriqn,
 + const char *target);
 +int
 +virISCSIRescanLUNs(const char *session);
 +
 +int
 +virISCSIScanTargets(const char *portal,
 +const char *initiatoriqn,
 +size_t *ntargetsret,
 +char ***targetsret);
 +int
 +virISCSINodeUpdate(const char *portal,
 +   const char *target,
 +   const char *name,
 +   const char *value);

And these 5 could have ATTRIBUTE_RETURN_CHECK too


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCHv2 6/8] Move functions using iscsiadm to viriscsi.c

2014-03-19 Thread Ján Tomko
Remove the 'StorageBackend' from names of the functions and fix
indentation.
---
 po/POTFILES.in  |   1 +
 src/Makefile.am |   1 +
 src/libvirt_private.syms|   9 +
 src/storage/storage_backend_iscsi.c | 498 ++--
 src/storage/storage_backend_iscsi.h |   4 -
 src/util/viriscsi.c | 498 
 src/util/viriscsi.h |  52 
 7 files changed, 588 insertions(+), 475 deletions(-)
 create mode 100644 src/util/viriscsi.c
 create mode 100644 src/util/viriscsi.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index efac7b2..5a4112a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -168,6 +168,7 @@ src/util/virhostdev.c
 src/util/viridentity.c
 src/util/virinitctl.c
 src/util/viriptables.c
+src/util/viriscsi.c
 src/util/virjson.c
 src/util/virkeyfile.c
 src/util/virlockspace.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 4fdd871..55427ed 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -113,6 +113,7 @@ UTIL_SOURCES =  
\
util/viridentity.c util/viridentity.h   \
util/virinitctl.c util/virinitctl.h \
util/viriptables.c util/viriptables.h   \
+   util/viriscsi.c util/viriscsi.h \
util/virjson.c util/virjson.h   \
util/virkeycode.c util/virkeycode.h \
util/virkeyfile.c util/virkeyfile.h \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c7e024d..d72a9af 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1359,6 +1359,15 @@ iptablesRemoveUdpInput;
 iptablesRemoveUdpOutput;
 
 
+# util/viriscsi.h
+virISCSIConnectionLogin;
+virISCSIConnectionLogout;
+virISCSIGetSession;
+virISCSINodeUpdate;
+virISCSIRescanLUNs;
+virISCSIScanTargets;
+
+
 # util/virjson.h
 virJSONValueArrayAppend;
 virJSONValueArrayGet;
diff --git a/src/storage/storage_backend_iscsi.c 
b/src/storage/storage_backend_iscsi.c
index b7a0380..7e7ffad 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -26,8 +26,6 @@
 #include dirent.h
 #include sys/wait.h
 #include string.h
-#include stdio.h
-#include regex.h
 #include fcntl.h
 #include unistd.h
 #include sys/stat.h
@@ -40,9 +38,9 @@
 #include vircommand.h
 #include virerror.h
 #include virfile.h
+#include viriscsi.h
 #include virlog.h
 #include virobject.h
-#include virrandom.h
 #include virstring.h
 #include viruuid.h
 
@@ -79,306 +77,14 @@ virStorageBackendISCSIPortal(virStoragePoolSourcePtr 
source)
 return portal;
 }
 
-struct virStorageBackendISCSISessionData {
-char *session;
-const char *devpath;
-};
-
-static int
-virStorageBackendISCSIExtractSession(char **const groups,
- void *opaque)
-{
-struct virStorageBackendISCSISessionData *data = opaque;
-
-if (STREQ(groups[1], data-devpath))
-return VIR_STRDUP(data-session, groups[0]);
-return 0;
-}
-
-static char *
-virStorageBackendISCSIGetSession(const char *devpath,
- bool probe)
-{
-/*
- * # iscsiadm --mode session
- * tcp: [1] 192.168.122.170:3260,1 demo-tgt-b
- * tcp: [2] 192.168.122.170:3260,1 demo-tgt-a
- *
- * Pull out 2nd and 4th fields
- */
-const char *regexes[] = {
-^tcp:\\s+\\[(\\S+)\\]\\s+\\S+\\s+(\\S+).*$
-};
-int vars[] = {
-2,
-};
-struct virStorageBackendISCSISessionData cbdata = {
-.session = NULL,
-.devpath = devpath,
-};
-
-virCommandPtr cmd = virCommandNewArgList(ISCSIADM, --mode, session, 
NULL);
-
-if (virCommandRunRegex(cmd,
-   1,
-   regexes,
-   vars,
-   virStorageBackendISCSIExtractSession,
-   cbdata, NULL)  0)
-goto cleanup;
-
-if (cbdata.session == NULL  !probe) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   %s, _(cannot find session));
-goto cleanup;
-}
-
-cleanup:
-virCommandFree(cmd);
-return cbdata.session;
-}
 
 static char *
 virStorageBackendISCSISession(virStoragePoolObjPtr pool,
   bool probe)
 {
-return virStorageBackendISCSIGetSession(pool-def-source.devices[0].path, 
probe);
-}
-
-
-#define LINE_SIZE 4096
-
-static int
-virStorageBackendIQNFound(const char *initiatoriqn,
-  char **ifacename)
-{
-int ret = IQN_MISSING, fd = -1;
-char ebuf[64];
-FILE *fp = NULL;
-char *line = NULL, *newline = NULL, *iqn = NULL, *token = NULL;
-virCommandPtr cmd = virCommandNewArgList(ISCSIADM,
- --mode, iface, NULL);
-
-if (VIR_ALLOC_N(line, LINE_SIZE) != 0) {
-