Skip to contentSkip to conversation

libbxl: add support for pvscsi, iteration 4

PATCH Superseded Olaf Hering 3 participants 22 messages Apr 17, 2015 – May 6, 2015

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover libbxl: add support for pvscsi, iteration 4

Port vscsi=[] and scsi-{attach,detach,list} commands from xend to libxl.

TODO:
- find better name for ->feature_host (perhaps ->sg_io as used in libvirt?)
- maybe use events instead of polling for "state" changes in reconfigure (libxl__wait_for_backend vs. libxl__ev_devstate_wait)
- add code to libvirt to actually allow SCSI and target passthrough. The current code is still a decade behind: it expects h:c:t:l notation...
- maybe adjust API for xl and libvirt to work directly with .idl provided structs instead of pass domU.cfg strings around

Changes between v3 and v4:
- Use libxl__device_nextid in libxl__device_vscsi_add
- Remove check for duplicate pdev assignment from libxl_device_vscsi_get_host
- Caller provides libxl_device_vscsi to libxl_device_vscsi_get_host
- Define LIBXL_HAVE_VSCSI
- Remove init_val from libxl_vscsi_pdev_type
- Move some functions from libxl to libxlu
- Introduce libxl_device_vscsi->next_vscsi_dev_id to handle holes
- Use Struct in KeyedUnion for ocaml idl
- docs: Mention pvscsi in xl and xl.cfg
- Turn feature_host into a defbool and add checking
- Support pvops and /dev/ nodes in config
- Wrap entire libxlu_vscsi.c with ifdef linux
- Set remove flag in libxl_device_vscsi_list
- Fix vscsiif path in xenstore-paths.markdown
- vscsiif.h: add some notes about xenstore layout
- Add copyright to libxlu_vscsi.c and libxl_vscsi.c
- Scripts to create and delete xen-scsiback nodes in Linux target framework
- Remove pvscsi.txt

Changes between v2 and v3:
- Adjust change for vscsiif.h
- Support "naa.wwn:lun" notation in pvops kernel
- Add example for pvops kernel using targetcli
patch required for python-rtslib:
http://article.gmane.org/gmane.linux.scsi.target.devel/8146
- Use vdev variable in libxl_device_vscsi_parse
http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg00734.html

Changes between v1 and v2:
- ported to current staging
http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg00030.html

Initial attempt was sent a year ago:
http://lists.xenproject.org/archives/html/xen-devel/2014-04/msg03958.html
Most comments are addressed.

This version has been tested with SLES as backend and frontend. This version has been tested with pvops as backend and SLES as frontend.

Olaf Hering (5):
vscsiif.h: fix WWN notation for p-dev property
docs: add vscsi to xenstore-paths.markdown
libxl: add support for vscsi
vscsiif.h: add some notes about xenstore layout Scripts to create and delete xen-scsiback nodes in Linux target
framework

 docs/man/xl.cfg.pod.5                    |  55 +++
 docs/man/xl.pod.1                        |  18 +
 docs/misc/xenstore-paths.markdown        |  10 +
 tools/libxl/Makefile                     |   2 +
 tools/libxl/libxl.c                      | 441 ++++++++++++++++++
 tools/libxl/libxl.h                      |  27 ++
 tools/libxl/libxl_create.c               |   1 +
 tools/libxl/libxl_device.c               |   2 +
 tools/libxl/libxl_internal.h             |  16 +
 tools/libxl/libxl_types.idl              |  56 +++
 tools/libxl/libxl_types_internal.idl     |   1 +
 tools/libxl/libxl_vscsi.c                | 271 +++++++++++
 tools/libxl/libxlu_vscsi.c               | 750 +++++++++++++++++++++++++++++++
 tools/libxl/libxlutil.h                  |  21 +
 tools/libxl/xl.h                         |   3 +
 tools/libxl/xl_cmdimpl.c                 | 184 +++++++-
 tools/libxl/xl_cmdtable.c                |  15 +
 tools/misc/Makefile                      |   4 +
 tools/misc/target-create-xen-scsiback.sh |  94 ++++
 tools/misc/target-delete-xen-scsiback.sh |  39 ++
 xen/include/public/io/vscsiif.h          |  70 ++-
 21 files changed, 2078 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_vscsi.c
 create mode 100644 tools/libxl/libxlu_vscsi.c
 create mode 100644 tools/misc/target-create-xen-scsiback.sh
 create mode 100644 tools/misc/target-delete-xen-scsiback.sh
#1 lore raw

PATCH v4 1/5 vscsiif.h: fix WWN notation for p-dev property

The pvops kernel expects either "naa.WWN:LUN" or "h:c:t:l" in the p-dev property. Add the missing :LUN part to the comment.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Tim Deegan <[email protected]>
---
 xen/include/public/io/vscsiif.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/public/io/vscsiif.h +1 -1
index 7a1db05..e8e38a9 100644
@@ -60,7 +60,7 @@
  *
  *      A string specifying the backend device: either a 4-tuple "h:c:t:l"
  *      (host, controller, target, lun, all integers), or a WWN (e.g.
- *      "naa.60014054ac780582").
+ *      "naa.60014054ac780582:0").
  *
  * v-dev
  *      Values:         string
#2 lore raw

Re: [PATCH v4 1/5] vscsiif.h: fix WWN notation for p-dev property

Quoted 2 lines · Olaf Hering

The pvops kernel expects either "naa.WWN:LUN" or "h:c:t:l" in the p-dev property. Add the missing :LUN part to the comment.

What about the older kernels that had said driver?

Quoted 29 lines
Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Tim Deegan <[email protected]>
---
 xen/include/public/io/vscsiif.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/public/io/vscsiif.h +1 -1
index 7a1db05..e8e38a9 100644
@@ -60,7 +60,7 @@
  *
  *      A string specifying the backend device: either a 4-tuple "h:c:t:l"
  *      (host, controller, target, lun, all integers), or a WWN (e.g.
- *      "naa.60014054ac780582").
+ *      "naa.60014054ac780582:0").
  *
  * v-dev
  *      Values:         string

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v4 1/5] vscsiif.h: fix WWN notation for p-dev property

Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Olaf Hering

The pvops kernel expects either "naa.WWN:LUN" or "h:c:t:l" in the p-dev property. Add the missing :LUN part to the comment.

What about the older kernels that had said driver?

Which older kernels? There is just 3.18+ of pvops.

Olaf

#4 lore raw

Re: [PATCH v4 1/5] vscsiif.h: fix WWN notation for p-dev property

Quoted 9 lines · Olaf Hering
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Olaf Hering

The pvops kernel expects either "naa.WWN:LUN" or "h:c:t:l" in the p-dev property. Add the missing :LUN part to the comment.

What about the older kernels that had said driver?

Which older kernels? There is just 3.18+ of pvops.

Xen classic kernels.

Quoted 2 lines

Olaf

#5 lore raw

Re: [PATCH v4 1/5] vscsiif.h: fix WWN notation for p-dev property

Quoted 4 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Olaf Hering
Quoted 1 line · Konrad Rzeszutek Wilk

On Fri, Apr 17, 2015 at 08:30:56AM +0000, Olaf Hering wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The pvops kernel expects either "naa.WWN:LUN" or "h:c:t:l" in the p-dev property. Add the missing :LUN part to the comment.

What about the older kernels that had said driver?

Which older kernels? There is just 3.18+ of pvops.

Xen classic kernels.

They handle just h:c:t:l in "p-dev".

Olaf

#6 lore raw

PATCH v4 2/5 docs: add vscsi to xenstore-paths.markdown

In reply to Olaf Hering
Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Tim Deegan <[email protected]>
---
 docs/misc/xenstore-paths.markdown | 10 ++++++++++
 1 file changed, 10 insertions(+)
docs/misc/xenstore-paths.markdown +10 -0
index d94ea9d..d7a5e30 100644
@@ -232,6 +232,11 @@ A virtual keyboard device frontend. Described by
 A virtual network device frontend. Described by
 [xen/include/public/io/netif.h][NETIF]
 
+#### ~/device/vscsi/$DEVID/* []
+
+A virtual scsi device frontend. Described by
+[xen/include/public/io/vscsiif.h][SCSIIF]
+
 #### ~/console/* []
 
 The primary PV console device. Described in [console.txt](console.txt)
@@ -302,6 +307,10 @@ A virtual keyboard device backend. Described by
 A virtual network device backend. Described by
 [xen/include/public/io/netif.h][NETIF]
 
+#### ~/backend/vscsi/$DOMID/$DEVID/* []
+
+A PV SCSI backend. Described in [pvscsi.txt](pvscsi.txt)
+
 #### ~/backend/console/$DOMID/$DEVID/* []
 
 A PV console backend. Described in [console.txt](console.txt)
@@ -403,6 +412,7 @@ ifb device used by Remus to buffer network output from the associated vif.
 [KBDIF]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,kbdif.h.html
 [LIBXLMEM]: http://xenbits.xen.org/docs/unstable/misc/libxl_memory.txt
 [NETIF]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,netif.h.html
+[SCSIIF]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,vscsiif.h.html
 [SI]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,xen.h.html#Struct_start_info
 [VCPU]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,vcpu.h.html
 [XSWIRE]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,xs_wire.h.html
#7 lore raw

Re: [PATCH v4 2/5] docs: add vscsi to xenstore-paths.markdown

docs/misc/xenstore-paths.markdown A virtual keyboard device backend. Described by · line 316

Quoted 11 lines · Olaf Hering
docs/misc/xenstore-paths.markdown +4 -0
@@ -302,6 +307,10 @@ A virtual keyboard device backend. Described by
 A virtual network device backend. Described by
 [xen/include/public/io/netif.h][NETIF]
 
+#### ~/backend/vscsi/$DOMID/$DEVID/* []
+
+A PV SCSI backend. Described in [pvscsi.txt](pvscsi.txt)
+
 #### ~/backend/console/$DOMID/$DEVID/* []
 
 A PV console backend. Described in [console.txt](console.txt)

This hunk still refers to the removed pvscsi.txt. Will be fixed in next version.

Olaf

#8 lore raw

PATCH v4 3/5 libxl: add support for vscsi

In reply to Olaf Hering

Port pvscsi support from xend to libxl:

vscsi=['pdev,vdev{,options}']
xl scsi-attach
xl scsi-detach
xl scsi-list

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 docs/man/xl.cfg.pod.5                |  55 +++
 docs/man/xl.pod.1                    |  18 +
 tools/libxl/Makefile                 |   2 +
 tools/libxl/libxl.c                  | 441 ++++++++++++++++++++
 tools/libxl/libxl.h                  |  27 ++
 tools/libxl/libxl_create.c           |   1 +
 tools/libxl/libxl_device.c           |   2 +
 tools/libxl/libxl_internal.h         |  16 +
 tools/libxl/libxl_types.idl          |  56 +++
 tools/libxl/libxl_types_internal.idl |   1 +
 tools/libxl/libxl_vscsi.c            | 271 +++++++++++++
 tools/libxl/libxlu_vscsi.c           | 750 +++++++++++++++++++++++++++++++++++
 tools/libxl/libxlutil.h              |  21 +
 tools/libxl/xl.h                     |   3 +
 tools/libxl/xl_cmdimpl.c             | 184 ++++++++-
 tools/libxl/xl_cmdtable.c            |  15 +
 16 files changed, 1862 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +55 -0
index f936dfc..d395e56 100644
@@ -510,6 +510,61 @@ value is optional if this is a guest domain.
 
 =back
 
+=item B<vscsi=[ "VSCSI_SPEC_STRING", "VSCSI_SPEC_STRING", ...]>
+
+Specifies the PVSCSI devices to be provided to the guest. PVSCSI passes
+dom0 SCSI devices as-is to the guest.
+
+Each VSCSI_SPEC_STRING consists of "pdev,vdev[,options]".
+'pdev' describes the physical device, preferable in a persistant format.
+'vdev' is the domU device in vHOST:CHANNEL:TARGET:LUN notation, all integers.
+'option' lists additional flags which a backend may recognize.
+
+The supported values for "pdev" and "option" depends on the used backend driver:
+
+=over 4
+
+=item B<Linux pvops>
+
+=over 4
+
+=item C<pdev>
+
+The backend driver in the pvops kernel is part of the Linux-IO Target framework
+(LIO). As such the SCSI devices have to be configured first with the tools
+provided by this framework, such as a xen-scsiback aware targetcli. The "pdev"
+in domU.cfg has to refer to a config item in that framework instead of the raw
+device. Ususally this is a WWN in the form of "na.WWN:LUN".
+
+=item C<option>
+
+No options recognized.
+
+=back
+
+=item B<Linux xenlinux>
+
+=over 4
+
+=item C<pdev>
+
+The dom0 device in either /dev/scsidev or pHOST:CHANNEL:TARGET:LUN notation.
+
+Its recommended to use persistant names "/dev/disk/by-*/*" to refer to a "pdev".
+The toolstack will translate this internally to "h:c:t:l" notation, which is how
+the backend driver will access the device. Using the "h:c:t:l" notation for
+"pdev" in domU.cfg is discouraged because this value will change across reboots,
+depending on the detection order in the OS.
+
+=item C<option>
+
+Currently only the option value "feature-host" is recognized. SCSI command
+emulation in backend driver is bypassed when "feature-host" is specified.
+
+=back
+
+=back
+
 =item B<vfb=[ "VFB_SPEC_STRING", "VFB_SPEC_STRING", ...]>
 
 Specifies the paravirtual framebuffer devices which should be supplied
docs/man/xl.pod.1 +18 -0
index 16783c8..19bdbfa 100644
@@ -1328,6 +1328,24 @@ List virtual trusted platform modules for a domain.
 
 =back
 
+=head2 PVSCSI DEVICES
+
+=over 4
+
+=item B<scsi-attach> I<domain-id> I<pdev> I<vdev>,I<[feature-host]>
+
+Creates a new vscsi device in the domain specified by I<domain-id>.
+
+=item B<scsi-detach> I<domain-id> I<vdev>
+
+Removes the vscsi device from domain specified by I<domain-id>.
+
+=item B<scsi-list> I<domain-id> I<[domain-id] ...>
+
+List vscsi devices for the domain specified by I<domain-id>.
+
+=back
+
 =head1 PCI PASS-THROUGH
 
 =over 4
tools/libxl/Makefile +2 -0
index 1b16598..79b3867 100644
@@ -91,6 +91,7 @@ endif
 LIBXL_LIBS += -lyajl
 
 LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
+			libxl_vscsi.o \
 			libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \
 			libxl_internal.o libxl_utils.o libxl_uuid.o \
 			libxl_json.o libxl_aoutils.o libxl_numa.o libxl_vnuma.o \
@@ -122,6 +123,7 @@ AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \
 AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c
 AUTOSRCS += _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c
 LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \
+	libxlu_vscsi.o \
 	libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o
 $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 
tools/libxl/libxl.c +441 -0

477 lines not on this page · raw message

tools/libxl/libxl.h +27 -0
index 6bc75c5..c594402 100644
@@ -736,6 +736,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
 #define LIBXL_HAVE_PSR_MBM 1
 #endif
 
+/*
+ * LIBXL_HAVE_VSCSI
+ *
+ * If this is defined, the PV SCSI feature is supported.
+ */
+#define LIBXL_HAVE_VSCSI 1
+
 typedef char **libxl_string_list;
 void libxl_string_list_dispose(libxl_string_list *sl);
 int libxl_string_list_length(const libxl_string_list *sl);
@@ -1252,6 +1259,26 @@ int libxl_device_channel_getinfo(libxl_ctx *ctx, uint32_t domid,
                                  libxl_device_channel *channel,
                                  libxl_channelinfo *channelinfo);
 
+/* Virtual SCSI */
+int libxl_device_vscsi_add(libxl_ctx *ctx, uint32_t domid,
+                           libxl_device_vscsi *vscsi,
+                           const libxl_asyncop_how *ao_how)
+                           LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_vscsi_remove(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_vscsi *vscsi,
+                              const libxl_asyncop_how *ao_how)
+                              LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_vscsi_destroy(libxl_ctx *ctx, uint32_t domid,
+                               libxl_device_vscsi *vscsi,
+                               const libxl_asyncop_how *ao_how)
+                               LIBXL_EXTERNAL_CALLERS_ONLY;
+
+libxl_device_vscsi *libxl_device_vscsi_list(libxl_ctx *ctx, uint32_t domid, int *num);
+int libxl_device_vscsi_getinfo(libxl_ctx *ctx, uint32_t domid,
+                               libxl_device_vscsi *vscsi_host,
+                               libxl_vscsi_dev *vscsi_dev,
+                               libxl_vscsiinfo *vscsiinfo);
+
 /* Virtual TPMs */
 int libxl_device_vtpm_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vtpm *vtpm,
                           const libxl_asyncop_how *ao_how)
tools/libxl/libxl_create.c +1 -0
index e5a343f..f67b4ce 100644
@@ -1157,6 +1157,7 @@ static void domcreate_rebuild_done(libxl__egc *egc,
     libxl__multidev_begin(ao, &dcs->multidev);
     dcs->multidev.callback = domcreate_launch_dm;
     libxl__add_disks(egc, ao, domid, d_config, &dcs->multidev);
+    libxl__add_vscsis(egc, ao, domid, d_config, &dcs->multidev);
     libxl__multidev_prepared(egc, &dcs->multidev, 0);
 
     return;
tools/libxl/libxl_device.c +2 -0
index 0c06dc4..111e348 100644
@@ -543,6 +543,7 @@ void libxl__multidev_prepared(libxl__egc *egc,
  * The following functions are defined:
  * libxl__add_disks
  * libxl__add_nics
+ * libxl__add_vscsis
  * libxl__add_vtpms
  */
 
@@ -562,6 +563,7 @@ void libxl__multidev_prepared(libxl__egc *egc,
 
 DEFINE_DEVICES_ADD(disk)
 DEFINE_DEVICES_ADD(nic)
+DEFINE_DEVICES_ADD(vscsi)
 DEFINE_DEVICES_ADD(vtpm)
 
 #undef DEFINE_DEVICES_ADD
tools/libxl/libxl_internal.h +16 -0
index 9c22309..d27936a 100644
@@ -2413,6 +2413,10 @@ _hidden void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
                                    libxl_device_nic *nic,
                                    libxl__ao_device *aodev);
 
+_hidden void libxl__device_vscsi_add(libxl__egc *egc, uint32_t domid,
+                                     libxl_device_vscsi *vscsi,
+                                     libxl__ao_device *aodev);
+
 _hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
                                    libxl_device_vtpm *vtpm,
                                    libxl__ao_device *aodev);
@@ -3037,6 +3041,10 @@ _hidden void libxl__add_nics(libxl__egc *egc, libxl__ao *ao, uint32_t domid,
                              libxl_domain_config *d_config,
                              libxl__multidev *multidev);
 
+_hidden void libxl__add_vscsis(libxl__egc *egc, libxl__ao *ao, uint32_t domid,
+                               libxl_domain_config *d_config,
+                               libxl__multidev *multidev);
+
 _hidden void libxl__add_vtpms(libxl__egc *egc, libxl__ao *ao, uint32_t domid,
                              libxl_domain_config *d_config,
                              libxl__multidev *multidev);
@@ -3608,6 +3616,13 @@ static inline void libxl__update_config_nic(libxl__gc *gc,
     libxl_mac_copy(CTX, &dst->mac, &src->mac);
 }
 
+static inline void libxl__update_config_vscsi(libxl__gc *gc,
+                                             libxl_device_vscsi *dst,
+                                             libxl_device_vscsi *src)
+{
+    dst->devid = src->devid;
+}
+
 static inline void libxl__update_config_vtpm(libxl__gc *gc,
                                              libxl_device_vtpm *dst,
                                              libxl_device_vtpm *src)
@@ -3620,6 +3635,7 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,
  * devices have same identifier. */
 #define COMPARE_DEVID(a, b) ((a)->devid == (b)->devid)
 #define COMPARE_DISK(a, b) (!strcmp((a)->vdev, (b)->vdev))
+#define COMPARE_VSCSI(a, b) ((a)->v_hst == (b)->v_hst)
 #define COMPARE_PCI(a, b) ((a)->func == (b)->func &&    \
                            (a)->bus == (b)->bus &&      \
                            (a)->dev == (b)->dev)
tools/libxl/libxl_types.idl +56 -0

74 lines not on this page · raw message

tools/libxl/libxl_types_internal.idl +1 -0
index 5e55685..84c44f5 100644
@@ -22,6 +22,7 @@ libxl__device_kind = Enumeration("device_kind", [
     (6, "VKBD"),
     (7, "CONSOLE"),
     (8, "VTPM"),
+    (9, "VSCSI"),
     ])
 
 libxl__console_backend = Enumeration("console_backend", [
tools/libxl/libxl_vscsi.c new file +271 -0

271 lines not on this page · raw message

tools/libxl/libxlu_vscsi.c new file +750 -0

750 lines not on this page · raw message

tools/libxl/libxlutil.h +21 -0
index 989605a..f5928fb 100644
@@ -114,6 +114,27 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str
 int xlu_vif_parse_rate(XLU_Config *cfg, const char *rate,
                        libxl_device_nic *nic);
 
+/* Append a vscsi device to a vscsi host */
+int xlu_vscsi_append_dev(libxl_ctx *ctx, libxl_device_vscsi *hst,
+                         libxl_vscsi_dev *dev);
+/* Fill vscsi_host with device described in str (pdev,vdev[,options]) */
+int xlu_vscsi_get_host(XLU_Config *config,
+                       libxl_ctx *ctx,
+                       uint32_t domid,
+                       const char *str,
+                       libxl_device_vscsi *vscsi_host);
+/* Parse config string and fill provided vscsi host and vscsi device */
+int xlu_vscsi_parse(XLU_Config *cfg, libxl_ctx *ctx, const char *str,
+                    libxl_device_vscsi *new_host,
+                    libxl_vscsi_dev *new_dev);
+/* Detach vscsi device described in config string (pdev,vdev[,options]) */
+int xlu_vscsi_detach(XLU_Config *cfg, libxl_ctx *ctx, uint32_t domid, char *str);
+/* Add vscsi device described in config string (pdev,vdev[,options]) to d_config */
+int xlu_vscsi_config_add(XLU_Config *cfg,
+                         libxl_ctx *ctx,
+                         const char *str,
+                         int *num_vscsis,
+                         libxl_device_vscsi **vscsis);
 #endif /* LIBXLUTIL_H */
 
 /*
tools/libxl/xl.h +3 -0
index 5bc138c..5c82688 100644
@@ -83,6 +83,9 @@ int main_channellist(int argc, char **argv);
 int main_blockattach(int argc, char **argv);
 int main_blocklist(int argc, char **argv);
 int main_blockdetach(int argc, char **argv);
+int main_vscsiattach(int argc, char **argv);
+int main_vscsilist(int argc, char **argv);
+int main_vscsidetach(int argc, char **argv);
 int main_vtpmattach(int argc, char **argv);
 int main_vtpmlist(int argc, char **argv);
 int main_vtpmdetach(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +183 -1

202 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +15 -0
index 9284887..80a7f53 100644
@@ -366,6 +366,21 @@ struct cmd_spec cmd_table[] = {
       "Destroy a domain's virtual block device",
       "<Domain> <DevId>",
     },
+    { "scsi-attach",
+      &main_vscsiattach, 1, 1,
+      "Attach a dom0 SCSI device to a domain.",
+      "<Domain> <PhysDevice> <VirtDevice>",
+    },
+    { "scsi-list",
+      &main_vscsilist, 0, 0,
+      "List all dom0 SCSI devices currently attached to a domain.",
+      "<Domain(s)>",
+    },
+    { "scsi-detach",
+      &main_vscsidetach, 0, 1,
+      "Detach a specified SCSI device from a domain.",
+      "<Domain> <VirtDevice>",
+    },
     { "vtpm-attach",
       &main_vtpmattach, 1, 1,
       "Create a new virtual TPM device",

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

Quoted 36 lines · Olaf Hering

Port pvscsi support from xend to libxl:

vscsi=['pdev,vdev{,options}']
xl scsi-attach
xl scsi-detach
xl scsi-list

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 docs/man/xl.cfg.pod.5                |  55 +++
 docs/man/xl.pod.1                    |  18 +
 tools/libxl/Makefile                 |   2 +
 tools/libxl/libxl.c                  | 441 ++++++++++++++++++++
 tools/libxl/libxl.h                  |  27 ++
 tools/libxl/libxl_create.c           |   1 +
 tools/libxl/libxl_device.c           |   2 +
 tools/libxl/libxl_internal.h         |  16 +
 tools/libxl/libxl_types.idl          |  56 +++
 tools/libxl/libxl_types_internal.idl |   1 +
 tools/libxl/libxl_vscsi.c            | 271 +++++++++++++
 tools/libxl/libxlu_vscsi.c           | 750 +++++++++++++++++++++++++++++++++++
 tools/libxl/libxlutil.h              |  21 +
 tools/libxl/xl.h                     |   3 +
 tools/libxl/xl_cmdimpl.c             | 184 ++++++++-
 tools/libxl/xl_cmdtable.c            |  15 +
 16 files changed, 1862 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +0 -0
index f936dfc..d395e56 100644

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 516

Quoted 7 lines
docs/man/xl.cfg.pod.5 +4 -0
@@ -510,6 +510,61 @@ value is optional if this is a guest domain.
 
 =back
 
+=item B<vscsi=[ "VSCSI_SPEC_STRING", "VSCSI_SPEC_STRING", ...]>
+
+Specifies the PVSCSI devices to be provided to the guest. PVSCSI passes
+dom0 SCSI devices as-is to the guest.

s/dom0/backend/

As in theory you could run an HVM guest with an SCSI device passed in - and use said backed to pass the SCSI device to another guest.

'as-is' ? I thought there were some filtering done in the backend?

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 519

Quoted 3 lines
docs/man/xl.cfg.pod.5 +3 -0
+
+Each VSCSI_SPEC_STRING consists of "pdev,vdev[,options]".
+'pdev' describes the physical device, preferable in a persistant format.

What is 'persistent' format?

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 527

Quoted 8 lines
docs/man/xl.cfg.pod.5 +8 -0
+'vdev' is the domU device in vHOST:CHANNEL:TARGET:LUN notation, all integers.
+'option' lists additional flags which a backend may recognize.
+
+The supported values for "pdev" and "option" depends on the used backend driver:
+
+=over 4
+
+=item B<Linux pvops>

s/pvops//

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 537

Quoted 10 lines
docs/man/xl.cfg.pod.5 +10 -0
+
+=over 4
+
+=item C<pdev>
+
+The backend driver in the pvops kernel is part of the Linux-IO Target framework
+(LIO). As such the SCSI devices have to be configured first with the tools
+provided by this framework, such as a xen-scsiback aware targetcli. The "pdev"
+in domU.cfg has to refer to a config item in that framework instead of the raw
+device. Ususally this is a WWN in the form of "na.WWN:LUN".

Usually.

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 545

Quoted 8 lines
docs/man/xl.cfg.pod.5 +8 -0
+
+=item C<option>
+
+No options recognized.
+
+=back
+
+=item B<Linux xenlinux>

xenlinux? Classic Xen?

Quoted 169 lines
docs/man/xl.cfg.pod.5 +22 -0
+
+=over 4
+
+=item C<pdev>
+
+The dom0 device in either /dev/scsidev or pHOST:CHANNEL:TARGET:LUN notation.
+
+Its recommended to use persistant names "/dev/disk/by-*/*" to refer to a "pdev".
+The toolstack will translate this internally to "h:c:t:l" notation, which is how
+the backend driver will access the device. Using the "h:c:t:l" notation for
+"pdev" in domU.cfg is discouraged because this value will change across reboots,
+depending on the detection order in the OS.
+
+=item C<option>
+
+Currently only the option value "feature-host" is recognized. SCSI command
+emulation in backend driver is bypassed when "feature-host" is specified.
+
+=back
+
+=back
+
 =item B<vfb=[ "VFB_SPEC_STRING", "VFB_SPEC_STRING", ...]>
 
 Specifies the paravirtual framebuffer devices which should be supplied
docs/man/xl.pod.1 +18 -0
index 16783c8..19bdbfa 100644
@@ -1328,6 +1328,24 @@ List virtual trusted platform modules for a domain.
 
 =back
 
+=head2 PVSCSI DEVICES
+
+=over 4
+
+=item B<scsi-attach> I<domain-id> I<pdev> I<vdev>,I<[feature-host]>
+
+Creates a new vscsi device in the domain specified by I<domain-id>.
+
+=item B<scsi-detach> I<domain-id> I<vdev>
+
+Removes the vscsi device from domain specified by I<domain-id>.
+
+=item B<scsi-list> I<domain-id> I<[domain-id] ...>
+
+List vscsi devices for the domain specified by I<domain-id>.
+
+=back
+
 =head1 PCI PASS-THROUGH
 
 =over 4
tools/libxl/Makefile +2 -0
index 1b16598..79b3867 100644
@@ -91,6 +91,7 @@ endif
 LIBXL_LIBS += -lyajl
 
 LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
+			libxl_vscsi.o \
 			libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \
 			libxl_internal.o libxl_utils.o libxl_uuid.o \
 			libxl_json.o libxl_aoutils.o libxl_numa.o libxl_vnuma.o \
@@ -122,6 +123,7 @@ AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \
 AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c
 AUTOSRCS += _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c
 LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \
+	libxlu_vscsi.o \
 	libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o
 $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 
tools/libxl/libxl.c +87 -0
index 511eef1..abe7d75 100644
@@ -2014,6 +2014,437 @@ static int libxl__resolve_domid(libxl__gc *gc, const char *name,
 }
 
 /******************************************************************************/
+
+static void libxl__device_vscsi_dev_backend_rm(libxl__gc *gc,
+                                              libxl_vscsi_dev *v,
+                                              xs_transaction_t t,
+                                              char *be_path,
+                                              int dev_wait)
+{
+    char *path, *val;
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+
+    path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
+    val = libxl__xs_read(gc, t, path);
+    LOG(DEBUG, "%s is %s", path, val);
+    if (val && strcmp(val, GCSPRINTF("%d", dev_wait)) == 0) {
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-devname", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-dev", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/v-dev", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+    } else {
+        LOG(ERROR, "%s has %s, expected %d", path, val, dev_wait);
+    }
+}
+
+static int libxl__device_vscsi_dev_backend_set(libxl__gc *gc,
+                                               libxl_vscsi_dev *v,
+                                               flexarray_t *back)
+{
+    int rc;
+    libxl_vscsi_hctl *hctl;
+
+    switch (v->pdev.type) {
+        case LIBXL_VSCSI_PDEV_TYPE_WWN:
+            flexarray_append_pair(back,
+                                  GCSPRINTF("vscsi-devs/dev-%u/p-dev", v->vscsi_dev_id),
+                                  v->pdev.u.wwn.m);
+            break;
+        case LIBXL_VSCSI_PDEV_TYPE_HCTL:
+            hctl = &v->pdev.u.hctl.m;
+            flexarray_append_pair(back,
+                                  GCSPRINTF("vscsi-devs/dev-%u/p-dev", v->vscsi_dev_id),
+                                  GCSPRINTF("%u:%u:%u:%u", hctl->hst, hctl->chn, hctl->tgt, hctl->lun));
+            break;
+        case LIBXL_VSCSI_PDEV_TYPE_INVALID:
+        default:
+            rc = ERROR_FAIL;
+            goto out;
+    }
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/p-devname", v->vscsi_dev_id),
+                          v->pdev.p_devname);
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/v-dev", v->vscsi_dev_id),
+                          GCSPRINTF("%u:%u:%u:%u", v->vdev.hst, v->vdev.chn, v->vdev.tgt, v->vdev.lun));
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/state", v->vscsi_dev_id),
+                          GCSPRINTF("%d", XenbusStateInitialising));
+    rc = 0;
+out:
+    return rc;
+}
+
+static int libxl__device_vscsi_new_backend(libxl__egc *egc,
+                                           libxl__ao_device *aodev,
+                                           libxl_device_vscsi *vscsi,
+                                           libxl_domain_config *d_config)
+{
+    STATE_AO_GC(aodev->ao);
+    int rc, i;
+    flexarray_t *back;
+    flexarray_t *front;
+    libxl_vscsi_dev *v;
+    xs_transaction_t t = XBT_NULL;
+
+    /* Prealloc key+value: 4 toplevel + 4 per device */
+    i = 2 * (4 + (4 * vscsi->num_vscsi_devs));
+    back = flexarray_make(gc, i, 1);
+    front = flexarray_make(gc, 2 * 2, 1);
+
+    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", aodev->dev->domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append_pair(back, "feature-host",
+                          libxl_defbool_val(vscsi->feature_host) ?
+                          "1" : "0");

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2113

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+
+    flexarray_append_pair(front, "backend-id", GCSPRINTF("%d", vscsi->backend_domid));
+    flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateInitialising));
+
+    for (i = 0; i < vscsi->num_vscsi_devs; i++) {
+        v = vscsi->vscsi_devs + i;
+        if (v->remove)
+            continue;
+        rc = libxl__device_vscsi_dev_backend_set(gc, v, back);
+        if (rc) goto out;

Don't you want 'return rc' as the out will try to call libxl__xs_transaction_abort?

Quoted 28 lines
tools/libxl/libxl.c +28 -0
+    }
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
+
+        rc = libxl__device_exists(gc, t, aodev->dev);
+        if (rc < 0) goto out;
+        if (rc == 1) {              /* already exists in xenstore */
+            LOG(ERROR, "device already exists in xenstore");
+            rc = ERROR_DEVICE_EXISTS;
+            goto out;
+        }
+
+        if (aodev->update_json) {
+            rc = libxl__set_domain_configuration(gc, aodev->dev->domid, d_config);
+            if (rc) goto out;
+        }
+
+        libxl__device_generic_add(gc, t, aodev->dev,
+                                  libxl__xs_kvs_of_flexarray(gc, back,
+                                                             back->count),
+                                  libxl__xs_kvs_of_flexarray(gc, front,
+                                                             front->count),
+                                  NULL);
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2151

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        if (rc < 0) goto out;
+    }
+
+    libxl__wait_device_connection(egc, aodev);
+    rc = 0;
+
+out:
+    libxl__xs_transaction_abort(gc, &t);
+    return rc;
+}

Stopped here as I had to run to a meeting.

#10 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

Quoted 6 lines · Konrad Rzeszutek Wilk

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 516

Quoted 4 lines · Olaf Hering

+=item B<vscsi=[ "VSCSI_SPEC_STRING", "VSCSI_SPEC_STRING", ...]>

docs/man/xl.cfg.pod.5 +3 -0
+
+Specifies the PVSCSI devices to be provided to the guest. PVSCSI passes
+dom0 SCSI devices as-is to the guest.

s/dom0/backend/

I will make that change.

Quoted 2 lines

As in theory you could run an HVM guest with an SCSI device passed in - and use said backed to pass the SCSI device to another guest.

Sounds interesting. I assume you meant "backend"? How will the domU talk to the other domU? Not sure if my libxl change covers that use case, and how I would be able to verify such functionality. Hopefully merging my series will not depend on such use case.

Quoted 1 line

'as-is' ? I thought there were some filtering done in the backend?

Perhaps 'passthrough with filtering'? I will remove it.

Quoted 3 lines
Quoted 2 lines

+Each VSCSI_SPEC_STRING consists of "pdev,vdev[,options]". +'pdev' describes the physical device, preferable in a persistant format.

What is 'persistent' format?

Anything that uses identifiers provided by the hardware, like serial numbers. /dev/disk/by-*/* for example. The h:c:t:l notation is not persistant because the "h" part will change across reboots.

Quoted 9 lines

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 545

Quoted 8 lines
docs/man/xl.cfg.pod.5 +8 -0
+
+=item C<option>
+
+No options recognized.
+
+=back
+
+=item B<Linux xenlinux>

xenlinux? Classic Xen?

Anything based on linux-2.6.18-xen.hg. I will adjust this to "Linux based on classic xen kernel"

Quoted 9 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2113

Quoted 8 lines
tools/libxl/libxl.c +7 -0
+static int libxl__device_vscsi_new_backend(libxl__egc *egc,
+                                           libxl__ao_device *aodev,
+                                           libxl_device_vscsi *vscsi,
+                                           libxl_domain_config *d_config)
+{
 
+        rc = libxl__device_vscsi_dev_backend_set(gc, v, back);
+        if (rc) goto out;

Don't you want 'return rc' as the out will try to call libxl__xs_transaction_abort?

The current code works because t is initialized to XBT_NULL, and libxl__xs_transaction_abort will do nothing in that case. I will adjust this as you suggested.

Olaf

#11 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

Quoted 9 lines · Olaf Hering
Quoted 6 lines · Konrad Rzeszutek Wilk

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 516

Quoted 4 lines · Olaf Hering

+=item B<vscsi=[ "VSCSI_SPEC_STRING", "VSCSI_SPEC_STRING", ...]>

docs/man/xl.cfg.pod.5 +3 -0
+
+Specifies the PVSCSI devices to be provided to the guest. PVSCSI passes
+dom0 SCSI devices as-is to the guest.

s/dom0/backend/

Quoted 6 lines

I will make that change.

Quoted 2 lines

As in theory you could run an HVM guest with an SCSI device passed in - and use said backed to pass the SCSI device to another guest.

Sounds interesting. I assume you meant "backend"? How will the domU talk

Yes, backend.

Quoted 1 line

to the other domU? Not sure if my libxl change covers that use case, and

Using the ring-buffer? Communicate via the Xenstore?

Quoted 2 lines

how I would be able to verify such functionality. Hopefully merging my series will not depend on such use case.

Right, not dependent on it.

Quoted 5 lines
Quoted 2 lines

'as-is' ? I thought there were some filtering done in the backend?

Perhaps 'passthrough with filtering'? I will remove it.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

+Each VSCSI_SPEC_STRING consists of "pdev,vdev[,options]". +'pdev' describes the physical device, preferable in a persistant format.

What is 'persistent' format?

Anything that uses identifiers provided by the hardware, like serial numbers. /dev/disk/by-*/* for example. The h:c:t:l notation is not persistant because the "h" part will change across reboots.

You might want to define what you mean by that. Or include the example (/dev/disk/by-*/*).

Quoted 11 lines
Quoted 10 lines

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 545

Quoted 9 lines
docs/man/xl.cfg.pod.5 +8 -0
+
+=item C<option>
+
+No options recognized.
+
+=back
+
+=item B<Linux xenlinux>

xenlinux? Classic Xen?

Quoted 2 lines

Anything based on linux-2.6.18-xen.hg. I will adjust this to "Linux based on classic xen kernel"

Excellent!

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
tools/libxl/libxl.c +5 -0
+static int libxl__device_vscsi_new_backend(libxl__egc *egc,
+                                           libxl__ao_device *aodev,
+                                           libxl_device_vscsi *vscsi,
+                                           libxl_domain_config *d_config)
+{
Quoted 7 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+        rc = libxl__device_vscsi_dev_backend_set(gc, v, back);
+        if (rc) goto out;

Don't you want 'return rc' as the out will try to call libxl__xs_transaction_abort?

The current code works because t is initialized to XBT_NULL, and libxl__xs_transaction_abort will do nothing in that case. I will adjust this as you suggested.

Thanks.

Quoted 2 lines

Olaf

#12 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

In reply to Olaf Hering
Quoted 11 lines · Olaf Hering
Quoted 6 lines · Konrad Rzeszutek Wilk

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 516

Quoted 4 lines · Olaf Hering

+=item B<vscsi=[ "VSCSI_SPEC_STRING", "VSCSI_SPEC_STRING", ...]>

docs/man/xl.cfg.pod.5 +3 -0
+
+Specifies the PVSCSI devices to be provided to the guest. PVSCSI passes
+dom0 SCSI devices as-is to the guest.

s/dom0/backend/

I will make that change.

Quoted 7 lines
Quoted 2 lines

As in theory you could run an HVM guest with an SCSI device passed in - and use said backed to pass the SCSI device to another guest.

Sounds interesting. I assume you meant "backend"? How will the domU talk to the other domU? Not sure if my libxl change covers that use case, and how I would be able to verify such functionality. Hopefully merging my series will not depend on such use case.

We can already do that with network driver domain. DomUs communicate via xenstore.

The first step is to not use anything hardcoded domid in you xenstore paths, i.e. do not make assumption on the domain that runs the backend.

Wei.

#13 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

Quoted 2 lines · Wei Liu

The first step is to not use anything hardcoded domid in you xenstore paths, i.e. do not make assumption on the domain that runs the backend.

Once someone wants that for pvscsi the vscsi=[] syntax has to be adjusted to also recognize another string.

Olaf

#14 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

Quoted 8 lines · Olaf Hering
Quoted 2 lines · Wei Liu

The first step is to not use anything hardcoded domid in you xenstore paths, i.e. do not make assumption on the domain that runs the backend.

Once someone wants that for pvscsi the vscsi=[] syntax has to be adjusted to also recognize another string.

Normally this is done in the spce string with backend= option. The default backend is Dom0 (0).

I don't think you need to implement this feature at this point, just keep in mind to not implement a protocol that's prevents us from using another domain as backend.

Wei.

Quoted 1 line

Olaf

#15 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

In reply to Olaf Hering
Quoted 36 lines · Olaf Hering

Port pvscsi support from xend to libxl:

vscsi=['pdev,vdev{,options}']
xl scsi-attach
xl scsi-detach
xl scsi-list

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 docs/man/xl.cfg.pod.5                |  55 +++
 docs/man/xl.pod.1                    |  18 +
 tools/libxl/Makefile                 |   2 +
 tools/libxl/libxl.c                  | 441 ++++++++++++++++++++
 tools/libxl/libxl.h                  |  27 ++
 tools/libxl/libxl_create.c           |   1 +
 tools/libxl/libxl_device.c           |   2 +
 tools/libxl/libxl_internal.h         |  16 +
 tools/libxl/libxl_types.idl          |  56 +++
 tools/libxl/libxl_types_internal.idl |   1 +
 tools/libxl/libxl_vscsi.c            | 271 +++++++++++++
 tools/libxl/libxlu_vscsi.c           | 750 +++++++++++++++++++++++++++++++++++
 tools/libxl/libxlutil.h              |  21 +
 tools/libxl/xl.h                     |   3 +
 tools/libxl/xl_cmdimpl.c             | 184 ++++++++-
 tools/libxl/xl_cmdtable.c            |  15 +
 16 files changed, 1862 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +0 -0
index f936dfc..d395e56 100644

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 519

Quoted 10 lines
docs/man/xl.cfg.pod.5 +7 -0
@@ -510,6 +510,61 @@ value is optional if this is a guest domain.
 
 =back
 
+=item B<vscsi=[ "VSCSI_SPEC_STRING", "VSCSI_SPEC_STRING", ...]>
+
+Specifies the PVSCSI devices to be provided to the guest. PVSCSI passes
+dom0 SCSI devices as-is to the guest.
+
+Each VSCSI_SPEC_STRING consists of "pdev,vdev[,options]".
+'pdev' describes the physical device, preferable in a persistant format.

"persistent", and please explain when "persistent format" is.

Quoted 6 lines
docs/man/xl.cfg.pod.5 +6 -0
+'vdev' is the domU device in vHOST:CHANNEL:TARGET:LUN notation, all integers.
+'option' lists additional flags which a backend may recognize.
+
+The supported values for "pdev" and "option" depends on the used backend driver:
+
+=over 4

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 535

Quoted 10 lines
docs/man/xl.cfg.pod.5 +10 -0
+
+=item B<Linux pvops>
+
+=over 4
+
+=item C<pdev>
+
+The backend driver in the pvops kernel is part of the Linux-IO Target framework
+(LIO). As such the SCSI devices have to be configured first with the tools
+provided by this framework, such as a xen-scsiback aware targetcli. The "pdev"

What is "targetcli"?

Quoted 7 lines
docs/man/xl.cfg.pod.5 +7 -0
+in domU.cfg has to refer to a config item in that framework instead of the raw
+device. Ususally this is a WWN in the form of "na.WWN:LUN".
+
+=item C<option>
+
+No options recognized.
+

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 552

Quoted 10 lines
docs/man/xl.cfg.pod.5 +10 -0
+=back
+
+=item B<Linux xenlinux>
+
+=over 4
+
+=item C<pdev>
+
+The dom0 device in either /dev/scsidev or pHOST:CHANNEL:TARGET:LUN notation.
+

What is vHOST? What is pHOST?

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 553

Quoted 1 line
docs/man/xl.cfg.pod.5 +1 -0
+Its recommended to use persistant names "/dev/disk/by-*/*" to refer to a "pdev".

"It's" "persistent"

Quoted 71 lines
docs/man/xl.cfg.pod.5 +14 -0
+The toolstack will translate this internally to "h:c:t:l" notation, which is how
+the backend driver will access the device. Using the "h:c:t:l" notation for
+"pdev" in domU.cfg is discouraged because this value will change across reboots,
+depending on the detection order in the OS.
+
+=item C<option>
+
+Currently only the option value "feature-host" is recognized. SCSI command
+emulation in backend driver is bypassed when "feature-host" is specified.
+
+=back
+
+=back
+
 =item B<vfb=[ "VFB_SPEC_STRING", "VFB_SPEC_STRING", ...]>
 
 Specifies the paravirtual framebuffer devices which should be supplied
docs/man/xl.pod.1 +18 -0
index 16783c8..19bdbfa 100644
@@ -1328,6 +1328,24 @@ List virtual trusted platform modules for a domain.
 
 =back
 
+=head2 PVSCSI DEVICES
+
+=over 4
+
+=item B<scsi-attach> I<domain-id> I<pdev> I<vdev>,I<[feature-host]>
+
+Creates a new vscsi device in the domain specified by I<domain-id>.
+
+=item B<scsi-detach> I<domain-id> I<vdev>
+
+Removes the vscsi device from domain specified by I<domain-id>.
+
+=item B<scsi-list> I<domain-id> I<[domain-id] ...>
+
+List vscsi devices for the domain specified by I<domain-id>.
+
+=back
+
 =head1 PCI PASS-THROUGH
 
 =over 4
tools/libxl/Makefile +2 -0
index 1b16598..79b3867 100644
@@ -91,6 +91,7 @@ endif
 LIBXL_LIBS += -lyajl
 
 LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
+			libxl_vscsi.o \
 			libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \
 			libxl_internal.o libxl_utils.o libxl_uuid.o \
 			libxl_json.o libxl_aoutils.o libxl_numa.o libxl_vnuma.o \
@@ -122,6 +123,7 @@ AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \
 AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c
 AUTOSRCS += _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c
 LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \
+	libxlu_vscsi.o \
 	libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o
 $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 
tools/libxl/libxl.c +0 -0
index 511eef1..abe7d75 100644

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2021

Quoted 8 lines
tools/libxl/libxl.c +5 -0
@@ -2014,6 +2014,437 @@ static int libxl__resolve_domid(libxl__gc *gc, const char *name,
 }
 
 /******************************************************************************/
+
+static void libxl__device_vscsi_dev_backend_rm(libxl__gc *gc,
+                                              libxl_vscsi_dev *v,
+                                              xs_transaction_t t,
+                                              char *be_path,

const char *be_path

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2025

Quoted 4 lines
tools/libxl/libxl.c +4 -0
+                                              int dev_wait)
+{
+    char *path, *val;
+    libxl_ctx *ctx = libxl__gc_owner(gc);

You can just use CTX macro.

Quoted 5 lines
tools/libxl/libxl.c +5 -0
+
+    path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
+    val = libxl__xs_read(gc, t, path);
+    LOG(DEBUG, "%s is %s", path, val);
+    if (val && strcmp(val, GCSPRINTF("%d", dev_wait)) == 0) {

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2040

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-devname", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-dev", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/v-dev", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);

Some lines are too long. Please wrap them properly.

But can you not simplify this by removing be_path all together?

Also this function should return error number -- you probably don't want caller to commence should things go wrong here.

Quoted 25 lines
tools/libxl/libxl.c +25 -0
+    } else {
+        LOG(ERROR, "%s has %s, expected %d", path, val, dev_wait);
+    }
+}
+
+static int libxl__device_vscsi_dev_backend_set(libxl__gc *gc,
+                                               libxl_vscsi_dev *v,
+                                               flexarray_t *back)
+{
+    int rc;
+    libxl_vscsi_hctl *hctl;
+
+    switch (v->pdev.type) {
+        case LIBXL_VSCSI_PDEV_TYPE_WWN:
+            flexarray_append_pair(back,
+                                  GCSPRINTF("vscsi-devs/dev-%u/p-dev", v->vscsi_dev_id),
+                                  v->pdev.u.wwn.m);
+            break;
+        case LIBXL_VSCSI_PDEV_TYPE_HCTL:
+            hctl = &v->pdev.u.hctl.m;
+            flexarray_append_pair(back,
+                                  GCSPRINTF("vscsi-devs/dev-%u/p-dev", v->vscsi_dev_id),
+                                  GCSPRINTF("%u:%u:%u:%u", hctl->hst, hctl->chn, hctl->tgt, hctl->lun));
+            break;
+        case LIBXL_VSCSI_PDEV_TYPE_INVALID:

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2075

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        default:
+            rc = ERROR_FAIL;
+            goto out;
+    }
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/p-devname", v->vscsi_dev_id),
+                          v->pdev.p_devname);
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/v-dev", v->vscsi_dev_id),
+                          GCSPRINTF("%u:%u:%u:%u", v->vdev.hst, v->vdev.chn, v->vdev.tgt, v->vdev.lun));
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/state", v->vscsi_dev_id),
+                          GCSPRINTF("%d", XenbusStateInitialising));

Please fix the lines that are too long.

Quoted 22 lines
tools/libxl/libxl.c +22 -0
+    rc = 0;
+out:
+    return rc;
+}
+
+static int libxl__device_vscsi_new_backend(libxl__egc *egc,
+                                           libxl__ao_device *aodev,
+                                           libxl_device_vscsi *vscsi,
+                                           libxl_domain_config *d_config)
+{
+    STATE_AO_GC(aodev->ao);
+    int rc, i;
+    flexarray_t *back;
+    flexarray_t *front;
+    libxl_vscsi_dev *v;
+    xs_transaction_t t = XBT_NULL;
+
+    /* Prealloc key+value: 4 toplevel + 4 per device */
+    i = 2 * (4 + (4 * vscsi->num_vscsi_devs));
+    back = flexarray_make(gc, i, 1);
+    front = flexarray_make(gc, 2 * 2, 1);
+

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2107

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", aodev->dev->domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append_pair(back, "feature-host",
+                          libxl_defbool_val(vscsi->feature_host) ?
+                          "1" : "0");
+
+    flexarray_append_pair(front, "backend-id", GCSPRINTF("%d", vscsi->backend_domid));
+    flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateInitialising));
+

Lines too long.

Quoted 40 lines
tools/libxl/libxl.c +40 -0
+    for (i = 0; i < vscsi->num_vscsi_devs; i++) {
+        v = vscsi->vscsi_devs + i;
+        if (v->remove)
+            continue;
+        rc = libxl__device_vscsi_dev_backend_set(gc, v, back);
+        if (rc) goto out;
+    }
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
+
+        rc = libxl__device_exists(gc, t, aodev->dev);
+        if (rc < 0) goto out;
+        if (rc == 1) {              /* already exists in xenstore */
+            LOG(ERROR, "device already exists in xenstore");
+            rc = ERROR_DEVICE_EXISTS;
+            goto out;
+        }
+
+        if (aodev->update_json) {
+            rc = libxl__set_domain_configuration(gc, aodev->dev->domid, d_config);
+            if (rc) goto out;
+        }
+
+        libxl__device_generic_add(gc, t, aodev->dev,
+                                  libxl__xs_kvs_of_flexarray(gc, back,
+                                                             back->count),
+                                  libxl__xs_kvs_of_flexarray(gc, front,
+                                                             front->count),
+                                  NULL);
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out;
+    }
+
+    libxl__wait_device_connection(egc, aodev);
+    rc = 0;
+

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2157

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+out:
+    libxl__xs_transaction_abort(gc, &t);
+    return rc;
+}
+
+static int libxl__device_vscsi_reconfigure(libxl__egc *egc,
+                                           libxl__ao_device *aodev,
+                                           libxl_device_vscsi *vscsi,
+                                           libxl_domain_config *d_config,
+                                           char *be_path,

const char *

Quoted 54 lines
tools/libxl/libxl.c +54 -0
+                                           int *dev_wait)
+{
+    STATE_AO_GC(aodev->ao);
+    int rc, i, be_state, be_wait;
+    char *dev_path, *state_path, *state_val;
+    flexarray_t *back;
+    libxl_vscsi_dev *v;
+    xs_transaction_t t = XBT_NULL;
+    bool do_reconfigure = false;
+
+    /* Prealloc key+value: 1 toplevel + 4 per device */
+    i = 2 * (1 + (4 * vscsi->num_vscsi_devs));
+    back = flexarray_make(gc, i, 1);
+
+    state_path = GCSPRINTF("%s/state", be_path);
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
+
+        state_val = libxl__xs_read(gc, t, state_path);
+        LOG(DEBUG, "%s is %s", state_path, state_val);
+        if (!state_val) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+
+        be_state = atoi(state_val);
+        switch (be_state) {
+            case XenbusStateUnknown:
+            case XenbusStateInitialising:
+            case XenbusStateClosing:
+            case XenbusStateClosed:
+            default:
+                /* The backend is in a bad state */
+                rc = ERROR_FAIL;
+                goto out;
+            case XenbusStateInitialised:
+            case XenbusStateReconfiguring:
+            case XenbusStateReconfigured:
+                /* Backend is still busy, caller has to retry */
+                rc = ERROR_NOT_READY;
+                goto out;
+            case XenbusStateInitWait:
+                /* The frontend did not connect yet */
+                be_wait = XenbusStateInitWait;
+                if (dev_wait)
+                    *dev_wait = XenbusStateInitialising;
+                do_reconfigure = false;
+                break;
+            case XenbusStateConnected:
+                /* The backend can handle reconfigure */
+                be_wait = XenbusStateConnected;
+                if (dev_wait)

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2221

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+                    *dev_wait = XenbusStateClosed;
+                flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateReconfiguring));
+                do_reconfigure = true;
+                break;
+        }
+
+        /* Append new device or trigger removal */
+        for (i = 0; i < vscsi->num_vscsi_devs; i++) {
+            v = vscsi->vscsi_devs + i;
+            unsigned int nb = 0;

Move this line at the beginning of this block. I think you will hit a gcc warning here, won't you?

Quoted 26 lines
tools/libxl/libxl.c +26 -0
+            dev_path = GCSPRINTF("%s/vscsi-devs/dev-%u", be_path, v->vscsi_dev_id);
+            /* Preserve existing device */
+            if (libxl__xs_directory(gc, XBT_NULL, dev_path, &nb) && nb) {
+                /* Trigger device removal by forwarding state to XenbusStateClosing */
+                if (do_reconfigure && v->remove)
+                    flexarray_append_pair(back,
+                                          GCSPRINTF("vscsi-devs/dev-%u/state", v->vscsi_dev_id),
+                                          GCSPRINTF("%d", XenbusStateClosing));
+                continue;
+            }
+            rc = libxl__device_vscsi_dev_backend_set(gc, v, back);
+            if (rc) goto out;
+        }
+
+        if (aodev->update_json) {
+            rc = libxl__set_domain_configuration(gc, aodev->dev->domid, d_config);
+            if (rc) goto out;
+        }
+
+        libxl__xs_writev(gc, t, be_path,
+                         libxl__xs_kvs_of_flexarray(gc, back, back->count));
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out;
+    }

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2257

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+
+    if (do_reconfigure) {
+        /* Poll for backend change */
+        rc = libxl__wait_for_backend(gc, be_path, GCSPRINTF("%d", be_wait));
+        if (rc) goto out;
+    }
+    rc = 0;
+
+out:
+    LOG(ERROR, "%u: rc %d", __LINE__, rc);

Remove this line.

Quoted 23 lines
tools/libxl/libxl.c +23 -0
+    libxl__xs_transaction_abort(gc, &t);
+    return rc;
+}
+
+static int libxl__device_from_vscsi(libxl__gc *gc, uint32_t domid,
+                                    libxl_device_vscsi *vscsi,
+                                    libxl__device *device)
+{
+    device->backend_domid = vscsi->backend_domid;
+    device->devid         = vscsi->devid;
+    device->domid         = domid;
+    device->backend_kind  = LIBXL__DEVICE_KIND_VSCSI;
+    device->kind          = LIBXL__DEVICE_KIND_VSCSI;
+
+    return 0;
+}
+
+void libxl__device_vscsi_add(libxl__egc *egc, uint32_t domid,
+                             libxl_device_vscsi *vscsi,
+                             libxl__ao_device *aodev)
+{
+    STATE_AO_GC(aodev->ao);
+    libxl__device *device;

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2290

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+    char *be_path;
+    unsigned int be_dirs = 0;
+    int rc;
+    libxl_domain_config d_config;
+    libxl_device_vscsi vscsi_saved;
+    libxl__domain_userdata_lock *lock = NULL;
+
+    libxl_domain_config_init(&d_config);
+
+    /* In case of vscsi the copy remains identical to the provided input */

This comment is confusing.

Quoted 25 lines
tools/libxl/libxl.c +25 -0
+    libxl_device_vscsi_init(&vscsi_saved);
+    libxl_device_vscsi_copy(CTX, &vscsi_saved, vscsi);
+
+    if (vscsi->devid == -1) {
+        if ((vscsi->devid = libxl__device_nextid(gc, domid, "vscsi")) < 0) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+    }
+
+    /* Adjust copy */
+    libxl__update_config_vscsi(gc, &vscsi_saved, vscsi);
+
+    GCNEW(device);
+    rc = libxl__device_from_vscsi(gc, domid, vscsi, device);
+    if (rc) goto out;
+
+    if (aodev->update_json) {
+        lock = libxl__lock_domain_userdata(gc, domid);
+        if (!lock) {
+            rc = ERROR_LOCK_FAIL;
+            goto out;
+        }
+
+        rc = libxl__get_domain_configuration(gc, domid, &d_config);

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2325

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        if (rc) goto out;
+
+        /* Replace or append the copy to the domain config */
+        DEVICE_ADD(vscsi, vscsis, domid, &vscsi_saved, COMPARE_VSCSI, &d_config);
+    }
+
+    aodev->dev = device;
+
+    be_path = libxl__device_backend_path(gc, aodev->dev);
+    if (libxl__xs_directory(gc, XBT_NULL, be_path, &be_dirs)) {

This looks bogus. Shouldn't you use a real transaction here and in the following two functions?

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2330

Quoted 5 lines
tools/libxl/libxl.c +5 -0
+        rc = libxl__device_vscsi_reconfigure(egc, aodev, vscsi, &d_config, be_path, NULL);
+        if (rc)
+            goto out;
+        /* Notify that this is done */
+        aodev->callback(egc, aodev);

And this is for? You can just do this in out path, right?

Quoted 27 lines
tools/libxl/libxl.c +27 -0
+    } else {
+        rc = libxl__device_vscsi_new_backend(egc, aodev, vscsi, &d_config);
+        if (rc)
+            goto out;
+    }
+
+    rc = 0;
+out:
+    if (lock) libxl__unlock_domain_userdata(lock);
+    libxl_device_vscsi_dispose(&vscsi_saved);
+    libxl_domain_config_dispose(&d_config);
+    aodev->rc = rc;
+    if (rc) aodev->callback(egc, aodev);
+    return;
+}
+
+static void libxl__device_vscsi_dev_rm(libxl__egc *egc,
+                                       libxl_device_vscsi *vscsi,
+                                       libxl__ao_device *aodev)
+{
+    STATE_AO_GC(aodev->ao);
+    char *be_path;
+    int rc, i, dev_wait;
+    libxl_domain_config d_config;
+    libxl__domain_userdata_lock *lock = NULL;
+    libxl_vscsi_dev *v;
+    xs_transaction_t t = XBT_NULL;

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2367

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+
+    libxl_domain_config_init(&d_config);
+
+    if (vscsi->devid == -1) {
+        rc = ERROR_INVAL;
+        goto out;
+    }
+
+    /* No other code will traverse device list, update json with removal info */
+    if (aodev->update_json) {

When is update_json set to true?

Note that in DEFINE_DEVICE_ADD update_json is set to true. But in you patch there doesn't seem to be code that does this.

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2380

Quoted 13 lines
tools/libxl/libxl.c +13 -0
+        lock = libxl__lock_domain_userdata(gc, aodev->dev->domid);
+        if (!lock) {
+            rc = ERROR_LOCK_FAIL;
+            goto out;
+        }
+
+        rc = libxl__get_domain_configuration(gc, aodev->dev->domid, &d_config);
+        if (rc) goto out;
+
+        /* Replace the item in the domain config */
+        DEVICE_ADD(vscsi, vscsis, aodev->dev->domid, vscsi, COMPARE_VSCSI, &d_config);
+    }
+

Actually, what fields inside vscsi structure are updated in this case?

Quoted 20 lines
tools/libxl/libxl.c +20 -0
+    be_path = libxl__device_backend_path(gc, aodev->dev);
+    rc = libxl__device_vscsi_reconfigure(egc, aodev, vscsi, &d_config, be_path, &dev_wait);
+    if (rc) goto out;
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
+
+        for (i = 0; i < vscsi->num_vscsi_devs; i++) {
+            v = vscsi->vscsi_devs + i;
+            if (v->remove)
+                libxl__device_vscsi_dev_backend_rm(gc, v, t, be_path, dev_wait);
+        }
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out;
+    }
+
+    rc = 0;

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2410

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+
+out:
+    if (lock) libxl__unlock_domain_userdata(lock);
+    libxl_domain_config_dispose(&d_config);
+    aodev->rc = rc;
+    /* Notify that this is done */
+    aodev->callback(egc, aodev);
+}
+
+/* Extended variant of DEFINE_DEVICE_REMOVE to handle reconfigure */

I have a very dumb question, what is "reconfigure"? Is this property of vscsi device? What does this suppose to do?

Quoted 26 lines
tools/libxl/libxl.c +26 -0
+                              libxl_device_vscsi *vscsi,
+                              const libxl_asyncop_how *ao_how)
+{
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__device *device;
+    libxl__ao_device *aodev;
+    int rc, i;
+    unsigned int remaining = vscsi->num_vscsi_devs;
+
+    GCNEW(device);
+    rc = libxl__device_from_vscsi(gc, domid, vscsi, device);
+    if (rc != 0) goto out;
+
+    GCNEW(aodev);
+    libxl__prepare_ao_device(ao, aodev);
+    aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
+    aodev->dev = device;
+    aodev->callback = device_addrm_aocomplete;
+    aodev->force = 0;
+
+    for (i = 0; i < vscsi->num_vscsi_devs; i++) {
+        if (vscsi->vscsi_devs[i].remove)
+            remaining--;
+    }
+
+    LOG(DEBUG, "%u: v_hst %u, %u of %u remaining", domid, vscsi->v_hst, remaining, vscsi->num_vscsi_devs);

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2447

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+    if (remaining)
+        libxl__device_vscsi_dev_rm(egc, vscsi, aodev);
+    else
+        libxl__initiate_device_remove(egc, aodev);
+
+out:
+    if (rc) return AO_ABORT(rc);
+    return AO_INPROGRESS;
+}
+

The rest of this patch is mostly parser, declarations and xl stuff. I've omitted the reset for now...

Wei.

#16 lore raw

Re: [PATCH v4 3/5] libxl: add support for vscsi

Quoted 3 lines · Wei Liu
Quoted 1 line · Olaf Hering

+'pdev' describes the physical device, preferable in a persistant format.

"persistent", and please explain when "persistent format" is.

Done.

Quoted 4 lines

docs/man/xl.cfg.pod.5 value is optional if this is a guest domain. · line 535

Quoted 3 lines
docs/man/xl.cfg.pod.5 +3 -0
+The backend driver in the pvops kernel is part of the Linux-IO Target framework
+(LIO). As such the SCSI devices have to be configured first with the tools
+provided by this framework, such as a xen-scsiback aware targetcli. The "pdev"

What is "targetcli"?

A tool to setup the various backend/frontend drivers of the Linux target IO framework. http://linux-iscsi.org/wiki/Targetcli
In fact the underlying python-rtslib has to be aware of xen-scsiback.

Quoted 2 lines
Quoted 1 line

+The dom0 device in either /dev/scsidev or pHOST:CHANNEL:TARGET:LUN notation.

What is vHOST? What is pHOST?

This refers to the "physical" SCSI host in the backend domain, and vHOST is the "index number" of a SCSI host presented to the guest.

Quoted 2 lines
Quoted 1 line

+Its recommended to use persistant names "/dev/disk/by-*/*" to refer to a "pdev".

"It's" "persistent"

Done.

Quoted 14 lines
Quoted 4 lines
tools/libxl/libxl.c +4 -0
+    path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
+    val = libxl__xs_read(gc, t, path);
+    LOG(DEBUG, "%s is %s", path, val);
+    if (val && strcmp(val, GCSPRINTF("%d", dev_wait)) == 0) {

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2040

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-devname", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-dev", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u/v-dev", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
+        path = GCSPRINTF("%s/vscsi-devs/dev-%u", be_path, v->vscsi_dev_id);
+        xs_rm(ctx->xsh, t, path);
Quoted 2 lines

Some lines are too long. Please wrap them properly. But can you not simplify this by removing be_path all together?

Done.

Quoted 2 lines

Also this function should return error number -- you probably don't want caller to commence should things go wrong here.

Why would anyone care about failed xs_rm? The state was forwarded and the domU is in unknown state if anything happens here. Also that vscsi-devs/dev-N path will not be used again.

Quoted 7 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2075

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/p-devname", v->vscsi_dev_id),
+                          v->pdev.p_devname);
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/v-dev", v->vscsi_dev_id),
+                          GCSPRINTF("%u:%u:%u:%u", v->vdev.hst, v->vdev.chn, v->vdev.tgt, v->vdev.lun));
+    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/state", v->vscsi_dev_id),
+                          GCSPRINTF("%d", XenbusStateInitialising));

Please fix the lines that are too long.

I did adjustments, but getting below 80 makes it look broken. I'm willing to donate wider editor windows.

Quoted 10 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2106

Quoted 9 lines
tools/libxl/libxl.c +9 -0
+    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", aodev->dev->domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append_pair(back, "feature-host",
+                          libxl_defbool_val(vscsi->feature_host) ?
+                          "1" : "0");
+
+    flexarray_append_pair(front, "backend-id", GCSPRINTF("%d", vscsi->backend_domid));
+    flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateInitialising));

Lines too long.

Getting below 80 makes it look broken.

Quoted 6 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2221

Quoted 4 lines
tools/libxl/libxl.c +4 -0
+        /* Append new device or trigger removal */
+        for (i = 0; i < vscsi->num_vscsi_devs; i++) {
+            v = vscsi->vscsi_devs + i;
+            unsigned int nb = 0;

Move this line at the beginning of this block. I think you will hit a gcc warning here, won't you?

No warning, -Werror would have caught this. I think -std=gnu99 allows this. I have flipped these two lines.

Quoted 2 lines
Quoted 1 line

+ /* In case of vscsi the copy remains identical to the provided input */

This comment is confusing.

What is confusing about it? "*vscsi == vscsi_saved". I will remove the comment.

Quoted 4 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2325

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+    be_path = libxl__device_backend_path(gc, aodev->dev);
+    if (libxl__xs_directory(gc, XBT_NULL, be_path, &be_dirs)) {

This looks bogus. Shouldn't you use a real transaction here and in the following two functions?

Not sure if that can be racy. Should the for-loop to retry the transaction be in this function? After all that thing is protected by the userdata lock.

Quoted 6 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2330

Quoted 5 lines
tools/libxl/libxl.c +5 -0
+        rc = libxl__device_vscsi_reconfigure(egc, aodev, vscsi, &d_config, be_path, NULL);
+        if (rc)
+            goto out;
+        /* Notify that this is done */
+        aodev->callback(egc, aodev);

And this is for? You can just do this in out path, right?

This has to be called unconditionally, the outpath does it only in case of failure.

Quoted 17 lines
Quoted 15 lines
tools/libxl/libxl.c +15 -0
+    } else {
+        rc = libxl__device_vscsi_new_backend(egc, aodev, vscsi, &d_config);
+        if (rc)
+            goto out;
+    }
+
+    rc = 0;
+out:
+    if (lock) libxl__unlock_domain_userdata(lock);
+    libxl_device_vscsi_dispose(&vscsi_saved);
+    libxl_domain_config_dispose(&d_config);
+    aodev->rc = rc;
+    if (rc) aodev->callback(egc, aodev);
+    return;
+}
Quoted 6 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2367

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+    /* No other code will traverse device list, update json with removal info */
+    if (aodev->update_json) {

When is update_json set to true?

Note that in DEFINE_DEVICE_ADD update_json is set to true. But in you patch there doesn't seem to be code that does this.

Right, somehow this got lost.

Quoted 3 lines

tools/libxl/libxl.c static int libxl__resolve_domid(libxl__gc *gc, const char *name, · line 2378

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+        /* Replace the item in the domain config */
+        DEVICE_ADD(vscsi, vscsis, aodev->dev->domid, vscsi, COMPARE_VSCSI, &d_config);

Actually, what fields inside vscsi structure are updated in this case?

The essential part is the ->vscsi_devs array, and the ->remove flag in each subdevice.

Quoted 4 lines
Quoted 1 line

+/* Extended variant of DEFINE_DEVICE_REMOVE to handle reconfigure */

I have a very dumb question, what is "reconfigure"? Is this property of vscsi device? What does this suppose to do?

Its XenbusStateReconfiguring, which tells the backend to rescan the vscsi-devs directory. vscsi and pci do this because they have the single_host-many_devices concept.

Thanks for the review. I will resend the current state later today.

Olaf

#17 lore raw

PATCH v4 4/5 vscsiif.h: add some notes about xenstore layout

In reply to Olaf Hering
Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Tim Deegan <[email protected]>
---
 xen/include/public/io/vscsiif.h | 68 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
xen/include/public/io/vscsiif.h +68 -0
index e8e38a9..6aaba22 100644
@@ -104,6 +104,74 @@
  *      response structures.
  */
 
+/*
+ * Xenstore format in practice
+ * ===========================
+ * 
+ * The backend driver uses a single_host:many_devices notation to manage domU
+ * devices. Everything is stored in /local/domain/0/backend/vscsi/. The
+ * xenstore layout looks like this:
+ * 
+ *     <domid>/<vhost>/feature-host = "0"
+ *     <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0"
+ *     <domid>/<vhost>/frontend-id = "<domid>"
+ *     <domid>/<vhost>/online = "1"
+ *     <domid>/<vhost>/state = "4"
+ *     <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1" or "naa.wwn:lun"
+ *     <domid>/<vhost>/vscsi-devs/dev-0/state = "4"
+ *     <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0"
+ *     <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2"
+ *     <domid>/<vhost>/vscsi-devs/dev-1/state = "4"
+ *     <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0"
+ * 
+ * The frontend driver maintains its state in
+ * /local/domain/<domid>/device/vscsi/.
+ * 
+ *     <vhost>/backend = "/local/domain/0/backend/vscsi/<domid>/<vhost>"
+ *     <vhost>/backend-id = "0"
+ *     <vhost>/event-channel = "20"
+ *     <vhost>/ring-ref = "43"
+ *     <vhost>/state = "4"
+ *     <vhost>/vscsi-devs/dev-0/state = "4"
+ *     <vhost>/vscsi-devs/dev-1/state = "4"
+ * 
+ * In addition to the entries for backend and frontend these flags are stored
+ * for the toolstack:
+ * 
+ *     <domid>/<vhost>/vscsi-devs/dev-1/p-devname = "/dev/$device"
+ * 
+ * 
+ * Backend/frontend protocol
+ * =========================
+ * 
+ * To create a vhost along with a device:
+ *     <domid>/<vhost>/feature-host = "0"
+ *     <domid>/<vhost>/frontend = "/local/domain/<domid>/device/vscsi/0"
+ *     <domid>/<vhost>/frontend-id = "<domid>"
+ *     <domid>/<vhost>/online = "1"
+ *     <domid>/<vhost>/state = "1"
+ *     <domid>/<vhost>/vscsi-devs/dev-0/p-dev = "8:0:2:1"
+ *     <domid>/<vhost>/vscsi-devs/dev-0/state = "1"
+ *     <domid>/<vhost>/vscsi-devs/dev-0/v-dev = "0:0:0:0"
+ * Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-0/state become 4
+ * 
+ * To add another device to a vhost:
+ *     <domid>/<vhost>/state = "7"
+ *     <domid>/<vhost>/vscsi-devs/dev-1/p-dev = "8:0:2:2"
+ *     <domid>/<vhost>/vscsi-devs/dev-1/state = "1"
+ *     <domid>/<vhost>/vscsi-devs/dev-1/v-dev = "0:0:1:0"
+ * Wait for <domid>/<vhost>/state + <domid>/<vhost>/vscsi-devs/dev-1/state become 4
+ * 
+ * To remove a device from a vhost:
+ *     <domid>/<vhost>/state = "7"
+ *     <domid>/<vhost>/vscsi-devs/dev-1/state = "5"
+ * Wait for <domid>/<vhost>/state to become 4
+ * Wait for <domid>/<vhost>/vscsi-devs/dev-1/state become 6
+ * Remove <domid>/<vhost>/vscsi-devs/dev-1/{state,p-dev,v-dev,p-devname}
+ * Remove <domid>/<vhost>/vscsi-devs/dev-1/
+ *
+ */
+
 /* Requests from the frontend to the backend */
 
 /*
#18 lore raw

Re: [PATCH v4 4/5] vscsiif.h: add some notes about xenstore layout

Quoted 15 lines · Olaf Hering
Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Tim Deegan <[email protected]>
---
 xen/include/public/io/vscsiif.h | 68 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
xen/include/public/io/vscsiif.h +0 -0
index e8e38a9..6aaba22 100644

xen/include/public/io/vscsiif.h line 112

Quoted 9 lines
xen/include/public/io/vscsiif.h +6 -0
@@ -104,6 +104,74 @@
  *      response structures.
  */
 
+/*
+ * Xenstore format in practice
+ * ===========================
+ * 
+ * The backend driver uses a single_host:many_devices notation to manage domU
+ * devices. Everything is stored in /local/domain/0/backend/vscsi/. The

Don't assume backend domid to be 0.

Wei.

#19 lore raw

Re: [PATCH v4 4/5] vscsiif.h: add some notes about xenstore layout

Quoted 4 lines · Wei Liu
Quoted 2 lines · Olaf Hering

+ * The backend driver uses a single_host:many_devices notation to manage domU
+ * devices. Everything is stored in /local/domain/0/backend/vscsi/. The

Don't assume backend domid to be 0.

Once vscsi=[] understands such setup that number will change. But I will will adjust this variable to refer to <backend_domid>.

Olaf

#20 lore raw

PATCH v4 5/5 Scripts to create and delete xen-scsiback nodes in Linux target framework

In reply to Olaf Hering

Just to make them public, not meant for merging:
The scripts used during development to create a bunch of SCSI devices in dom0 using the Linux target framework. targetcli3 and rtslib3 is used.

A patch is required for python-rtslib:
http://article.gmane.org/gmane.linux.scsi.target.devel/8146

---
 tools/misc/Makefile                      |  4 ++
 tools/misc/target-create-xen-scsiback.sh | 94 ++++++++++++++++++++++++++++++++
 tools/misc/target-delete-xen-scsiback.sh | 39 +++++++++++++
 3 files changed, 137 insertions(+)
tools/misc/Makefile +4 -0
index ccd36af..be101d8 100644
@@ -32,6 +32,8 @@ INSTALL_SBIN += $(INSTALL_SBIN-y)
 
 # Everything to be installed in a private bin/
 INSTALL_PRIVBIN                += xenpvnetboot
+INSTALL_PRIVBIN                += target-create-xen-scsiback.sh
+INSTALL_PRIVBIN                += target-delete-xen-scsiback.sh
 
 # Everything to be installed
 TARGETS_ALL := $(INSTALL_BIN) $(INSTALL_SBIN) $(INSTALL_PRIVBIN)
@@ -42,6 +44,8 @@ TARGETS_COPY += xen-ringwatch
 TARGETS_COPY += xencons
 TARGETS_COPY += xencov_split
 TARGETS_COPY += xenpvnetboot
+TARGETS_COPY += target-create-xen-scsiback.sh
+TARGETS_COPY += target-delete-xen-scsiback.sh
 
 # Everything which needs to be built
 TARGETS_BUILD := $(filter-out $(TARGETS_COPY),$(TARGETS_ALL))
tools/misc/target-create-xen-scsiback.sh new file +94 -0

94 lines not on this page · raw message

tools/misc/target-delete-xen-scsiback.sh new file +39 -0
new file mode 100644
index 0000000..a90bd82
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+unset LANG
+unset ${!LC_*}
+set -x
+set -e
+
+targetcli --version
+
+configfs=/sys/kernel/config
+target_path=$configfs/target
+
+cd "${target_path}"
+cd xen-pvscsi
+for wwn in `ls -d naa.*`
+do
+	targetcli /xen-pvscsi delete $wwn
+done
+cd "${target_path}"
+cd core
+for name in `ls -d pscsi_*/*/wwn`
+do
+	name=${name%/wwn}
+	name=${name##*/}
+	targetcli /backstores/pscsi delete $name
+done
+cd "${target_path}"
+cd loopback
+for wwn in `ls -d naa.*`
+do
+	targetcli /loopback delete $wwn
+done
+cd "${target_path}"
+cd core
+for name in `ls -d fileio_*/*/wwn`
+do
+	name=${name%/wwn}
+	name=${name##*/}
+	targetcli /backstores/fileio delete $name
+done
#21 lore raw

Re: [PATCH v4 5/5] Scripts to create and delete xen-scsiback nodes in Linux target framework

Quoted 6 lines · Olaf Hering

Just to make them public, not meant for merging:
The scripts used during development to create a bunch of SCSI devices in dom0 using the Linux target framework. targetcli3 and rtslib3 is used.

A patch is required for python-rtslib:
http://article.gmane.org/gmane.linux.scsi.target.devel/8146

Because libvirt understands just h:c:t:l it is required to configure also an alias with the appropriate numbers. Otherwise xen-scsiback will not find its "p-dev".

tools/misc/target-create-xen-scsiback.sh +14 -0
index fc49c2e..e168a3e 100644
@@ -65,6 +65,19 @@ do
 		by_id="`echo ${vpd_uuid} | sed 's@-@@g;s@^\(.\{25\}\)\(.*\)@scsi-36001405\1@'`"
 		ln -sfvbn "/dev/disk/by-id/${by_id}" "${f_link}"
 
+		f_major=$((`stat --dereference --format=0x%t "${f_link}"`))
+		f_minor=$((`stat --dereference --format=0x%T "${f_link}"`))
+		if test -z "${f_major}" || test -z "${f_minor}"
+		then
+			exit 1
+		fi
+		f_alias=`ls -d /sys/dev/block/${f_major}:${f_minor}/device/scsi_device/*:*:*:*`
+		if test -z "${f_alias}"
+		then
+			exit 1
+		fi
+		f_alias=${f_alias##*/}
+
 		blockdev --rereadpt "${f_link}"
 		udevadm settle --timeout=4
 		echo 1,12,S | sfdisk "${f_link}"
@@ -87,6 +100,7 @@ do
 
 		targetcli /backstores/pscsi create "dev=${f_link}" "${pscsi_name}"
 		targetcli /xen-pvscsi/${pvscsi_wwn}/tpg1/luns create "/backstores/pscsi/${pscsi_name}" $lun
+		targetcli /xen-pvscsi/${pvscsi_wwn}/tpg1  set parameter alias=${f_alias%:*}
 
 		lun=$(( $lun + 1 ))
 	done