Skip to contentSkip to conversation

libbxl: add support for pvscsi, iteration 6

PATCH In review Olaf Hering 2 participants 10 messages Nov 13, 2015 – Feb 3, 2016

lore
Share & tools
lore
#0 lore raw

cover libbxl: add support for pvscsi, iteration 6

Note: just a rebase close to "RELEASE-4.6.0", with no substantial changes

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

libvirt uses its existing SCSI support:
http://lists.xenproject.org/archives/html/xen-devel/2015-04/msg02963.html

targetcli/rtslib has to be aware of xen-scsiback (upstream unresponsive):
http://article.gmane.org/gmane.linux.scsi.target.devel/8146

TODO:
- check if idl names should contain "ctrl" and "device"
- check if "detach <vdev>" can be done with single host/single device instead of the ->remove field
- check if a transaction should be used in libxl__device_vscsi_add
- maybe use events instead of polling for "state" changes in reconfigure (libxl__wait_for_backend vs. libxl__ev_devstate_wait)
- comply with tools/libxl/CODING_STYLE everywhere
- document pvscsi in xen wiki

Changes between v5 and v6:
- rebase to 'staging' (a7b39c8 and b7e7ad8)
- Fix off-by-one in xlu__vscsi_compare_udev
- xl.cfg: use options instead of option
- xl.cfg: fix grammar for pdev/options
- xl.cfg: fix Usually typo
- Remove next_vscsi_dev_id from libxl_device_vscsi
- Use XLU_WWN_LEN also in libxl_vscsi.c

Changes between v4 and v5:
- vscsiif.h: refer to backend_domid
- Set update_json in libxl_device_vscsi_remove
- Remove comment from libxl__device_vscsi_add
- Remove debug LOG from libxl__device_vscsi_reconfigure
- Move local nb variable in libxl__device_vscsi_reconfigure
- Make be_path const in libxl__device_vscsi_reconfigure
- Adjust libxl__device_vscsi_dev_backend_set to avoid long lines
- Adjust libxl__device_vscsi_dev_backend_rm to avoid long lines
- Use CTX in libxl__device_vscsi_dev_backend_rm
- Make be_path const in libxl__device_vscsi_dev_backend_rm
- xl.cfg: Its typo
- xl.cfg: Use persistent instead of persistant
- Rename feature_host to scsi_raw_cmds
- target-create-xen-scsiback.sh: detect pvops and xenlinux
- Wrap long lines in main_vscsilist
- Call libxl_vscsiinfo_dispose unconditional
- Let scsi-list print p-dev instead of p-devname
- Handle broken vscsi device entry in xenstore
- Split libxl__vscsi_fill_host from libxl_device_vscsi_list
- Make xlu_vscsi_append_dev static
- Remove reference to pvscsi.txt from xenstore-paths.markdown
- xl.cfg: update Linux and xenlinux
- xl.cfg: refer to backend domain instead of dom0
- xl.cfg: be more verbose what persistant format is
- return if libxl__device_vscsi_dev_backend_set fails in libxl__device_vscsi_new_backend
- target-create-xen-scsiback.sh: set also alias for libvirt
http://lists.xenproject.org/archives/html/xen-devel/2015-05/msg00523.html

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
http://lists.xenproject.org/archives/html/xen-devel/2015-04/msg01949.html

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                      | 440 ++++++++++++++++++
 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              |  55 +++
 tools/libxl/libxl_types_internal.idl     |   1 +
 tools/libxl/libxl_vscsi.c                | 273 +++++++++++
 tools/libxl/libxlu_vscsi.c               | 749 +++++++++++++++++++++++++++++++
 tools/libxl/libxlutil.h                  |  18 +
 tools/libxl/xl.h                         |   3 +
 tools/libxl/xl_cmdimpl.c                 | 205 ++++++++-
 tools/libxl/xl_cmdtable.c                |  15 +
 tools/misc/Makefile                      |   4 +
 tools/misc/target-create-xen-scsiback.sh | 135 ++++++
 tools/misc/target-delete-xen-scsiback.sh |  41 ++
 xen/include/public/io/vscsiif.h          |  70 ++-
 21 files changed, 2138 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_vscsi.c
 create mode 100644 tools/libxl/libxlu_vscsi.c
 create mode 100755 tools/misc/target-create-xen-scsiback.sh
 create mode 100755 tools/misc/target-delete-xen-scsiback.sh
#1 lore raw

PATCH 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

PATCH 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..b1c68ce 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.
+
 #### ~/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
#3 lore raw

PATCH 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                  | 440 ++++++++++++++++++++
 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          |  55 +++
 tools/libxl/libxl_types_internal.idl |   1 +
 tools/libxl/libxl_vscsi.c            | 273 +++++++++++++
 tools/libxl/libxlu_vscsi.c           | 749 +++++++++++++++++++++++++++++++++++
 tools/libxl/libxlutil.h              |  18 +
 tools/libxl/xl.h                     |   3 +
 tools/libxl/xl_cmdimpl.c             | 205 +++++++++-
 tools/libxl/xl_cmdtable.c            |  15 +
 16 files changed, 1879 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +55 -0
index b63846a..9b785cc 100644
@@ -517,6 +517,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
+SCSI devices from the backend domain to the guest.
+
+Each VSCSI_SPEC_STRING consists of "pdev,vdev[,options]".
+'pdev' describes the physical device, preferable in a persistent format such as /dev/disk/by-*/*.
+'vdev' is the domU device in vHOST:CHANNEL:TARGET:LUN notation, all integers.
+'options' lists additional flags which a backend may recognize.
+
+The supported values for "pdev" and "options" depends on the backend driver used:
+
+=over 4
+
+=item B<Linux>
+
+=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. Usually this is a WWN in the form of "na.WWN:LUN".
+
+=item C<options>
+
+No options recognized.
+
+=back
+
+=item B<Linux based on classic Xen kernel>
+
+=over 4
+
+=item C<pdev>
+
+The dom0 device in either /dev/scsidev or pHOST:CHANNEL:TARGET:LUN notation.
+
+It's recommended to use persistent 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<options>
+
+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 4279c7c..0674149 100644
@@ -1293,6 +1293,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 6ff5bee..2b2b859 100644
@@ -97,6 +97,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 \
@@ -139,6 +140,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 +440 -0

476 lines not on this page · raw message

tools/libxl/libxl.h +27 -0
index 168fedd..35f4b68 100644
@@ -821,6 +821,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
 #define LIBXL_HAVE_PCITOPOLOGY 1
 
 /*
+ * LIBXL_HAVE_VSCSI
+ *
+ * If this is defined, the PV SCSI feature is supported.
+ */
+#define LIBXL_HAVE_VSCSI 1
+
+/*
  * LIBXL_HAVE_SOCKET_BITMAP
  *
  * If this is defined, then libxl_socket_bitmap_alloc and
@@ -1446,6 +1453,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 f0fee00..639c8ef 100644
@@ -1150,6 +1150,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 8bb5e93..33f1ad2 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 b00add0..5ff3d00 100644
@@ -2562,6 +2562,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);
@@ -3280,6 +3284,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);
@@ -3940,6 +3948,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)
@@ -3952,6 +3967,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 +55 -0

73 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 +273 -0

273 lines not on this page · raw message

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

749 lines not on this page · raw message

tools/libxl/libxlutil.h +18 -0
index e81b644..db046a2 100644
@@ -118,6 +118,24 @@ int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *rdm, const char *str);
 int xlu_vif_parse_rate(XLU_Config *cfg, const char *rate,
                        libxl_device_nic *nic);
 
+/* 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 bdab125..877c695 100644
@@ -89,6 +89,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 +204 -1

223 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +15 -0
index fdc1ac6..11e1c26 100644
@@ -351,6 +351,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

#8 lore raw

PATCH 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..2c5f04a 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/<backend_domid>/backend/vscsi/.
+ * The xenstore layout looks like this (dom0 is assumed to be the backend_domid):
+ * 
+ *     <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 */
 
 /*
#9 lore raw

PATCH 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 | 135 +++++++++++++++++++++++++++++++
 tools/misc/target-delete-xen-scsiback.sh |  41 ++++++++++
 3 files changed, 180 insertions(+)
tools/misc/Makefile +4 -0
index c4490f3..3d5d75f 100644
@@ -34,6 +34,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)
@@ -44,6 +46,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 +135 -0

135 lines not on this page · raw message

tools/misc/target-delete-xen-scsiback.sh new file +41 -0

41 lines not on this page · raw message

#4 lore raw

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

In reply to Olaf Hering
Quoted 1 line · Olaf Hering

Port pvscsi support from xend to libxl:

How should code which converts devices from xenstore to json handle devices which got marked as "to be removed"?

In my pvscsi code I set XenbusStateClosing in the vscsidev, then XenbusStateReconfiguring in vscsictrl. This causes the backend/frontend to reevaluate the vscsi bus. During that timeframe some other code can walk xenstore and find such a device. In libxl__vscsi_fill_host below such device gets the ->remove flag. This flag is handled elsewhere to indicate that its not an active device anymore. IanC asked to remove the flag and I'm converting the code to work without such flag. The question still stands what to do with such devices when filling the list of vscsidevs on a vscsictrl. Is it up to the caller to inspect the state of each vscsidev to decide what to do with it? Or should the function below just skip the device right away?

I think in the current state the device would endup in d_config and in json.

Olaf

Quoted 51 lines
tools/libxl/libxl_vscsi.c new file +51 -0
+static void libxl__vscsi_fill_host(libxl__gc *gc,
+                                   const char *devs_path,
+                                   char **dev_dirs,
+                                   unsigned int ndev_dirs,
+                                   libxl_device_vscsi *v_hst)
+{
+    libxl_vscsi_dev *v_dev;
+    bool parsed_ok;
+    char *c, *p, *v, *s, *dev;
+    unsigned int vscsi_dev_id;
+    int i, r;
+
+    v_hst->vscsi_devs = libxl__malloc(NOGC, ndev_dirs * sizeof(*v_dev));
+    v_hst->num_vscsi_devs = ndev_dirs;
+    /* Fill each device connected to the host */
+    for (i = 0; i < ndev_dirs; i++, dev_dirs++) {
+        v_dev = v_hst->vscsi_devs + i;
+        libxl_vscsi_dev_init(v_dev);
+        parsed_ok = false;
+        r = sscanf(*dev_dirs, "dev-%u", &vscsi_dev_id);
+        if (r != 1) {
+            LOG(ERROR, "expected dev-N, got '%s'", *dev_dirs);
+            continue;
+        }
+
+        dev = GCSPRINTF("%s/%s", devs_path, *dev_dirs);
+        c = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/p-devname", dev));
+        p = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/p-dev", dev));
+        v = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/v-dev", dev));
+        s = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/state", dev));
+        LOG(DEBUG, "%s/state is %s", dev, s);
+        if (!(c && p && v && s)) {
+            LOG(ERROR, "p-devname '%s' p-dev '%s' v-dev '%s'", c, p, v);
+            continue;
+        }
+
+        parsed_ok = vscsi_parse_pdev(gc, v_dev, c, p, v);
+        switch (atoi(s)) {
+            case XenbusStateUnknown:
+            case XenbusStateInitialising:
+            case XenbusStateInitWait:
+            case XenbusStateInitialised:
+            case XenbusStateConnected:
+            case XenbusStateReconfiguring:
+            case XenbusStateReconfigured:
+                break;
+            case XenbusStateClosing:
+            case XenbusStateClosed:
+                v_dev->remove = true;
+                break;
+        }
#5 lore raw

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

(Note that I'm not very familiar with this, so what I'm talking might be non-sense, and please bear with me if I ask stupid questions.)

Quoted 19 lines · Olaf Hering
Quoted 1 line · Olaf Hering

Port pvscsi support from xend to libxl:

How should code which converts devices from xenstore to json handle devices which got marked as "to be removed"?

In my pvscsi code I set XenbusStateClosing in the vscsidev, then XenbusStateReconfiguring in vscsictrl. This causes the backend/frontend to reevaluate the vscsi bus. During that timeframe some other code can walk xenstore and find such a device. In libxl__vscsi_fill_host below such device gets the ->remove flag. This flag is handled elsewhere to indicate that its not an active device anymore. IanC asked to remove the flag and I'm converting the code to work without such flag. The question still stands what to do with such devices when filling the list of vscsidevs on a vscsictrl. Is it up to the caller to inspect the state of each vscsidev to decide what to do with it? Or should the function below just skip the device right away?

Quoted 2 lines

I think in the current state the device would endup in d_config and in json.

If it is to be removed, why don't you just filter it out and not have it in JSON at all? This is provided libxl won't rely on that to do proper clean-up I don't see the value of retaining them, and if libxl is relying on the JSON file to do clean-up the design is probably wrong.

In the mean time I will start (re-)reading this vscsi thing...

Wei.

#6 lore raw

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

Quoted 26 lines · Wei Liu

(Note that I'm not very familiar with this, so what I'm talking might be non-sense, and please bear with me if I ask stupid questions.)

Quoted 19 lines · Olaf Hering
Quoted 1 line · Olaf Hering

Port pvscsi support from xend to libxl:

How should code which converts devices from xenstore to json handle devices which got marked as "to be removed"?

In my pvscsi code I set XenbusStateClosing in the vscsidev, then XenbusStateReconfiguring in vscsictrl. This causes the backend/frontend to reevaluate the vscsi bus. During that timeframe some other code can walk xenstore and find such a device. In libxl__vscsi_fill_host below such device gets the ->remove flag. This flag is handled elsewhere to indicate that its not an active device anymore. IanC asked to remove the flag and I'm converting the code to work without such flag. The question still stands what to do with such devices when filling the list of vscsidevs on a vscsictrl. Is it up to the caller to inspect the state of each vscsidev to decide what to do with it? Or should the function below just skip the device right away?

Quoted 2 lines

I think in the current state the device would endup in d_config and in json.

Quoted 7 lines

If it is to be removed, why don't you just filter it out and not have it in JSON at all? This is provided libxl won't rely on that to do proper clean-up I don't see the value of retaining them, and if libxl is relying on the JSON file to do clean-up the design is probably wrong.

In the mean time I will start (re-)reading this vscsi thing...

BTW if you plan to post a new version please just go ahead. Don't wait for me to comment on this version.

Wei.

Quoted 1 line

Wei.

#7 lore raw

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

In reply to Wei Liu
Quoted 4 lines · Wei Liu

If it is to be removed, why don't you just filter it out and not have it in JSON at all? This is provided libxl won't rely on that to do proper clean-up I don't see the value of retaining them, and if libxl is relying on the JSON file to do clean-up the design is probably wrong.

In its current state my patch will skip a vscsidev in state 5+6 when collecting the various vscsi-devs/dev-N on a vscsictrl.

However right now its not entirely clear to me if that is correct. During scsi-attach the vscsidevs get added to JSON, but scsi-detach will not remove them from JSON. Thats just like ordinary devices. At what point must the JSON be synced with xenstore? I think at 'xl save/ migrate'.

I think I have to revisit this once I sent out the current state of my patches, which will not be before Friday this week.

Olaf