Re: [Libguestfs] [PATCH] VxFS Filesystem support to libguestfs

2023-09-14 Thread Richard W.M. Jones
On Thu, Jun 08, 2023 at 11:38:53AM +0100, Richard W.M. Jones wrote:
> From: Ravi Singh 

First, thanks to various people who helped me to get Infoscale Storage
installed.

I have questions ...

>  appliance/hostfiles.in|   4 ++
>  appliance/init|   2 +
>  daemon/Makefile.am|   7 +++
>  daemon/guestfsd.c |   3 +
>  daemon/listfs.ml  |  17 ++
>  daemon/vm.ml  |  68 ++
>  daemon/vm.mli |  24 
>  daemon/vxfs.c | 119 ++
>  daemon/vxvm_type.ml   |  17 ++
>  daemon/vxvm_type.mli  |  24 
>  generator/actions_core.ml |  32 ++
>  generator/proc_nr.ml  |   3 +
>  lib/MAX_PROC_NR   |   2 +-
>  po/POTFILES   |   1 +
>  14 files changed, 322 insertions(+), 1 deletion(-)
> 
> diff --git a/appliance/hostfiles.in b/appliance/hostfiles.in
> index e78c79bd34..e519ad1787 100644
> --- a/appliance/hostfiles.in
> +++ b/appliance/hostfiles.in
> @@ -17,3 +17,7 @@ dnl   OPENMANDRIVA=1 For OpenMandriva.
>  /etc/ld.so.cache
>  /lib/lsb/*
>  /usr/share/augeas/lenses/*.aug
> +/etc/vx/vxfs
> +/etc/vx/veki
> +/etc/vx/vxvm-startup

These are executable configuration files which start various services.
Later on, do_vxfs_start will test if these files exist and then run
them to bring up the vxfs services inside the appliance.  However I'm
not exactly sure how that could possibly work as these scripts refer
to programs that are not copied into the appliance.

> +/opt/VRTS/bin/fstyp

This is a symlink to /usr/lib/fs/vxfs/fstyp which is a binary.  While
it's not impossible for hostfiles.in to be used for scripts (like the
ones above) and binaries, it's better to use packagelist.in to list
the packages (ie. RPMs) you actually want to copy in.  For example:

# rpm -qf /usr/lib/fs/vxfs/fstyp
VRTSvxfs-8.0.2.-RHEL9.x86_64
]# rpm -qf /etc/vx/vxfs
VRTSvxfs-8.0.2.-RHEL9.x86_64
# rpm -qf /etc/vx/veki 
VRTSveki-8.0.2.-RHEL9.x86_64
# rpm -qf /etc/vx/vxvm-startup 
VRTSvxvm-8.0.2.-RHEL9.x86_64

Simply listing VRTSvxvm in packagelist.in would copy the whole package
into the appliance, including all those files, and (if the RPMs are
set up correctly) all dependencies that they need to run.

I actually can't understand how this can work as written.

> diff --git a/appliance/init b/appliance/init
> index d410566597..535a3d6b19 100755
> --- a/appliance/init
> +++ b/appliance/init
> @@ -22,6 +22,8 @@ mount -t proc /proc /proc
>  mount -t sysfs /sys /sys
>  # devtmpfs is required since udev 176
>  mount -t devtmpfs /dev /dev
> +# Create dev directory for all VxVM device files.
> +mkdir -p /dev/vx
>  ln -s /proc/self/fd /dev/fd
>  
>  # Parse the kernel command line early (must be after /proc is mounted).
> diff --git a/daemon/Makefile.am b/daemon/Makefile.am
> index bb2e58d014..8d3d9c8255 100644
> --- a/daemon/Makefile.am
> +++ b/daemon/Makefile.am
> @@ -51,6 +51,8 @@ generator_built = \
>   link.mli \
>   listfs.mli \
>   lvm.mli \
> + vm.mli \
> + vxvm_type.mli \
>   lvm_dm.mli \
>   md.mli \
>   mount.mli \
> @@ -208,6 +210,7 @@ guestfsd_SOURCES = \
>   wc.c \
>   xattr.c \
>   xfs.c \
> + vxfs.c \
>   yara.c \
>   zero.c \
>   zerofree.c
> @@ -294,6 +297,8 @@ SOURCES_MLI = \
>   link.mli \
>   listfs.mli \
>   lvm.mli \
> + vm.mli \
> + vxvm_type.mli \
>   lvm_dm.mli \
>   lvm_utils.mli \
>   md.mli \
> @@ -328,6 +333,8 @@ SOURCES_ML = \
>   ldm.ml \
>   link.ml \
>   lvm.ml \
> + vm.ml \
> + vxvm_type.ml \
>   lvm_utils.ml \
>   lvm_dm.ml \
>   findfs.ml \
> diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
> index 33c297de33..7b202ea53c 100644
> --- a/daemon/guestfsd.c
> +++ b/daemon/guestfsd.c
> @@ -273,6 +273,9 @@ main (int argc, char *argv[])
> */
>udev_settle ();
>  
> +  /* Start vxfs services */
> +  do_vxfs_start();
> +

This is added as a public API (see generator/actions_core.ml change
later).  But it seems like that wasn't intentional.  Do you intend
that programs using libguestfs would need to run 'guestfs_vxfs_start'
themselves?  And if so what would be the situation when that is
necessary?

If it's not necessary for this to be a public API then just make this
into a normal function.

>/* Send the magic length message which indicates that
> * userspace is up inside the guest.
> */
> diff --git a/daemon/listfs.ml b/daemon/listfs.ml
> index 2376b61dbc..10e32d8c04 100644
> --- a/daemon/listfs.ml
> +++ b/daemon/listfs.ml
> @@ -25,6 +25,11 @@ open Std_utils
>   * contain filesystems, so we filter them out.
>   *)
>  let rec list_filesystems () =
> +
> +  (* Check if the vxvm services are available. As we are trying to read
> +   * vxvm disk layout
> +   *)
> +  let has_vxvm = Optgroups.vxvm_available () in
>let has_lvm2 = Optgroups.lvm2_available () in
>let has_ldm = Optgroups.ldm_available 

[Libguestfs] [PATCH] VxFS Filesystem support to libguestfs

2023-06-08 Thread Richard W.M. Jones
From: Ravi Singh 

---
 appliance/hostfiles.in|   4 ++
 appliance/init|   2 +
 daemon/Makefile.am|   7 +++
 daemon/guestfsd.c |   3 +
 daemon/listfs.ml  |  17 ++
 daemon/vm.ml  |  68 ++
 daemon/vm.mli |  24 
 daemon/vxfs.c | 119 ++
 daemon/vxvm_type.ml   |  17 ++
 daemon/vxvm_type.mli  |  24 
 generator/actions_core.ml |  32 ++
 generator/proc_nr.ml  |   3 +
 lib/MAX_PROC_NR   |   2 +-
 po/POTFILES   |   1 +
 14 files changed, 322 insertions(+), 1 deletion(-)

diff --git a/appliance/hostfiles.in b/appliance/hostfiles.in
index e78c79bd34..e519ad1787 100644
--- a/appliance/hostfiles.in
+++ b/appliance/hostfiles.in
@@ -17,3 +17,7 @@ dnl   OPENMANDRIVA=1 For OpenMandriva.
 /etc/ld.so.cache
 /lib/lsb/*
 /usr/share/augeas/lenses/*.aug
+/etc/vx/vxfs
+/etc/vx/veki
+/etc/vx/vxvm-startup
+/opt/VRTS/bin/fstyp
diff --git a/appliance/init b/appliance/init
index d410566597..535a3d6b19 100755
--- a/appliance/init
+++ b/appliance/init
@@ -22,6 +22,8 @@ mount -t proc /proc /proc
 mount -t sysfs /sys /sys
 # devtmpfs is required since udev 176
 mount -t devtmpfs /dev /dev
+# Create dev directory for all VxVM device files.
+mkdir -p /dev/vx
 ln -s /proc/self/fd /dev/fd
 
 # Parse the kernel command line early (must be after /proc is mounted).
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index bb2e58d014..8d3d9c8255 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -51,6 +51,8 @@ generator_built = \
link.mli \
listfs.mli \
lvm.mli \
+   vm.mli \
+   vxvm_type.mli \
lvm_dm.mli \
md.mli \
mount.mli \
@@ -208,6 +210,7 @@ guestfsd_SOURCES = \
wc.c \
xattr.c \
xfs.c \
+   vxfs.c \
yara.c \
zero.c \
zerofree.c
@@ -294,6 +297,8 @@ SOURCES_MLI = \
link.mli \
listfs.mli \
lvm.mli \
+   vm.mli \
+   vxvm_type.mli \
lvm_dm.mli \
lvm_utils.mli \
md.mli \
@@ -328,6 +333,8 @@ SOURCES_ML = \
ldm.ml \
link.ml \
lvm.ml \
+   vm.ml \
+   vxvm_type.ml \
lvm_utils.ml \
lvm_dm.ml \
findfs.ml \
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 33c297de33..7b202ea53c 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -273,6 +273,9 @@ main (int argc, char *argv[])
*/
   udev_settle ();
 
+  /* Start vxfs services */
+  do_vxfs_start();
+
   /* Send the magic length message which indicates that
* userspace is up inside the guest.
*/
diff --git a/daemon/listfs.ml b/daemon/listfs.ml
index 2376b61dbc..10e32d8c04 100644
--- a/daemon/listfs.ml
+++ b/daemon/listfs.ml
@@ -25,6 +25,11 @@ open Std_utils
  * contain filesystems, so we filter them out.
  *)
 let rec list_filesystems () =
+
+  (* Check if the vxvm services are available. As we are trying to read
+   * vxvm disk layout
+   *)
+  let has_vxvm = Optgroups.vxvm_available () in
   let has_lvm2 = Optgroups.lvm2_available () in
   let has_ldm = Optgroups.ldm_available () in
 
@@ -53,6 +58,12 @@ let rec list_filesystems () =
   let mds = List.filter is_not_partitioned_device mds in
   List.iter (check_with_vfs_type ret) mds;
 
+  (* VxVM. *)
+  if has_vxvm then (
+let vxvm_vol = Vm.vxvm () in
+List.iter (check_with_vxvmvol_type ret) vxvm_vol
+  );
+
   (* LVM. *)
   if has_lvm2 then (
 let lvs = Lvm.lvs () in
@@ -192,3 +203,9 @@ and check_with_vfs_type ret device =
 
   else
 List.push_back ret (mountable, vfs_type)
+
+(* Check for the vxvm volume type *)
+and check_with_vxvmvol_type ret device =
+  let mountable = Mountable.of_device device in
+  let vxvmvol_typ = Vxvm_type.vxvmvol_type mountable in
+  List.push_back ret (mountable, vxvmvol_typ)
diff --git a/daemon/vm.ml b/daemon/vm.ml
new file mode 100644
index 00..d01b9e273d
--- /dev/null
+++ b/daemon/vm.ml
@@ -0,0 +1,68 @@
+open Unix
+open Printf
+
+open Std_utils
+open Str
+open Utils
+
+let rec vxvm () =
+  let a = command "vxdisk" ["-q"; "list"; "-p"; "-x"; "DG_NAME"] in
+  let lines = String.nsplit "\n" a in
+  let lines = List.map String.trim lines in
+  let lines = List.filter ((<>) "") lines in
+
+  (* Create a list of list *)
+  let lines = List.filter_map (
+fun line ->
+  let s = Str.regexp "[ \t\r\n]" in
+  let str = Str.bounded_split s line 2 in
+  match str with
+  | [ a; b ] ->
+Some (sprintf "%s" b)
+  | _-> None
+  ) lines in
+
+  (* Trim of all the whitespaces from each element of the list *)
+  let lines = List.map String.trim lines in
+
+  (* Skip the lines with "-" *)
+  let lines = List.filter ((<>) "-") lines in
+  let lines = List.sort_uniq compare lines in
+  let _ = List.iter (eprintf "%s") lines in
+
+  (* Import the disk group that is in the deported state *)
+  let _ = List.map (
+fun x ->
+  let r, out, 

[Libguestfs] [PATCH] VxFS Filesystem support to libguestfs

2023-06-08 Thread Richard W.M. Jones
Reposting this patch as a patch, original message here:
https://listman.redhat.com/archives/libguestfs/2023-June/031722.html


___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs