From: Paolo Bonzini Date: Thu, 21 Mar 2013 11:53:52 +0000 (+0100) Subject: secret: add iscsi to possible usage types X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=adba0701222efbf0a0e77d952d5a34c02cc88ffb;p=people%2Fliuw%2Flibxenctrl-split%2Flibvirt.git secret: add iscsi to possible usage types Signed-off-by: Paolo Bonzini --- diff --git a/docs/formatsecret.html.in b/docs/formatsecret.html.in index 01aff2d0e..c3c4a2597 100644 --- a/docs/formatsecret.html.in +++ b/docs/formatsecret.html.in @@ -66,6 +66,18 @@ device. Since 0.9.7.

+

Usage type "iscsi"

+ +

+ This secret is associated with an iSCSI target for CHAP authentication. + The <usage type='iscsi'> element must contain + a single target element that specifies a usage name + for the secret. The iSCSI secret can then be used by UUID or by + this usage name via the <auth> element of + a disk + device. Since 1.0.4. +

+

Example

diff --git a/docs/schemas/secret.rng b/docs/schemas/secret.rng
index e49bd5a70..d7b8f83fd 100644
--- a/docs/schemas/secret.rng
+++ b/docs/schemas/secret.rng
@@ -41,6 +41,7 @@
             
               
               
+              
               
             
           
@@ -67,4 +68,13 @@
     
   
 
+  
+    
+      iscsi
+    
+    
+      
+    
+  
+
 
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index f6a7affb6..45b56387a 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3649,6 +3649,7 @@ typedef enum {
     VIR_SECRET_USAGE_TYPE_NONE = 0,
     VIR_SECRET_USAGE_TYPE_VOLUME = 1,
     VIR_SECRET_USAGE_TYPE_CEPH = 2,
+    VIR_SECRET_USAGE_TYPE_ISCSI = 3,
 
 #ifdef VIR_ENUM_SENTINELS
     VIR_SECRET_USAGE_TYPE_LAST
diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 891af65b8..8842d9a69 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -36,7 +36,7 @@
 #define VIR_FROM_THIS VIR_FROM_SECRET
 
 VIR_ENUM_IMPL(virSecretUsageType, VIR_SECRET_USAGE_TYPE_LAST,
-              "none", "volume", "ceph")
+              "none", "volume", "ceph", "iscsi")
 
 void
 virSecretDefFree(virSecretDefPtr def)
@@ -57,6 +57,10 @@ virSecretDefFree(virSecretDefPtr def)
         VIR_FREE(def->usage.ceph);
         break;
 
+    case VIR_SECRET_USAGE_TYPE_ISCSI:
+        VIR_FREE(def->usage.target);
+        break;
+
     default:
         VIR_ERROR(_("unexpected secret usage type %d"), def->usage_type);
         break;
@@ -108,6 +112,15 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
         }
         break;
 
+    case VIR_SECRET_USAGE_TYPE_ISCSI:
+        def->usage.target = virXPathString("string(./usage/target)", ctxt);
+        if (!def->usage.target) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("iSCSI usage specified, but target is missing"));
+            return -1;
+        }
+        break;
+
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected secret usage type %d"),
@@ -262,6 +275,13 @@ virSecretDefFormatUsage(virBufferPtr buf,
         }
         break;
 
+    case VIR_SECRET_USAGE_TYPE_ISCSI:
+        if (def->usage.target != NULL) {
+            virBufferEscapeString(buf, "    %s\n",
+                                  def->usage.target);
+        }
+        break;
+
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected secret usage type %d"),
diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h
index 6079d5b6a..53517f99f 100644
--- a/src/conf/secret_conf.h
+++ b/src/conf/secret_conf.h
@@ -39,6 +39,7 @@ struct _virSecretDef {
     union {
         char *volume;               /* May be NULL */
         char *ceph;
+        char *target;
     } usage;
 };
 
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 5be33b9cb..c577817c5 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -149,6 +149,11 @@ secretFindByUsage(virSecretDriverStatePtr driver, int usageType, const char *usa
             if (STREQ(s->def->usage.ceph, usageID))
                 return s;
             break;
+
+        case VIR_SECRET_USAGE_TYPE_ISCSI:
+            if (STREQ(s->def->usage.target, usageID))
+                return s;
+            break;
         }
     }
     return NULL;
@@ -614,6 +619,9 @@ secretUsageIDForDef(virSecretDefPtr def)
     case VIR_SECRET_USAGE_TYPE_CEPH:
         return def->usage.ceph;
 
+    case VIR_SECRET_USAGE_TYPE_ISCSI:
+        return def->usage.target;
+
     default:
         return NULL;
     }