diff mbox

[7/8] scsi-disk: Implement 'alua_preferred' option

Message ID 1448636346-24641-8-git-send-email-hare@suse.de
State New
Headers show

Commit Message

Hannes Reinecke Nov. 27, 2015, 2:59 p.m. UTC
Implement an option to set the 'preferred path' bit in the
REPORT TARGET PORT GROUPS output.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 hw/scsi/scsi-disk.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
diff mbox

Patch

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index b3ab890..07e0c28 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -3411,6 +3411,38 @@  out:
     }
 }
 
+static void scsi_disk_get_alua_pref(Object *obj, Visitor *v, void *opaque,
+                                      const char *name, Error **errp)
+{
+    SCSIDiskState *s = OBJECT_CHECK(SCSIDiskState, obj, "scsi-disk");
+    bool pref = !!(s->alua_state & 0x80);
+
+    visit_type_bool(v, &pref, name, errp);
+}
+
+static void scsi_disk_set_alua_pref(Object *obj, Visitor *v, void *opaque,
+                                      const char *name, Error **errp)
+{
+    SCSIDiskState *s = OBJECT_CHECK(SCSIDiskState, obj, "scsi-disk");
+    bool pref;
+    Error *local_err = NULL;
+
+    visit_type_bool(v, &pref, name, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    if (pref) {
+        s->alua_state |= 0x80;
+    } else {
+        s->alua_state &= ~0x80;
+    }
+out:
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+
 static void scsi_disk_instance_initfn(Object *obj)
 {
     object_property_add(obj, "alua_state", "uint8",
@@ -3421,6 +3453,11 @@  static void scsi_disk_instance_initfn(Object *obj)
                         scsi_disk_get_alua_policy,
                         scsi_disk_set_alua_policy, NULL, NULL, NULL);
     object_property_set_str(obj, "", "alua_policy", NULL);
+
+    object_property_add(obj, "alua_preferred", "bool",
+                        scsi_disk_get_alua_pref,
+                        scsi_disk_set_alua_pref, NULL, NULL, NULL);
+    object_property_set_bool(obj, false, "alua_preferred", NULL);
 }
 
 static const TypeInfo scsi_disk_info = {