[Libguestfs] [PATCH stable-1.24] Fix fstab block device resolution for FreeBSD

Richard W.M. Jones rjones at redhat.com
Tue Nov 5 11:42:44 UTC 2013


On Tue, Nov 05, 2013 at 12:15:47PM +0200, Nikos Skalkotos wrote:
> The device name prefix for IDE hard drives used to be `ad' but now
> is `ada' (http://www.freebsd.org/doc/handbook/disks-naming.html).
> For virtio hard drives it is `vtbd'.
> 
> Under an MBR partition table a slice will be used, so the name of
> the first partitions will be either `ada0s1a' or `vtbd0s1a'. Under a
> GPT partition table, where no slice is needed, the name of the first
> partition will be either `ada0p1' or `vtbd0p1'.
> 
> Signed-off-by: Nikos Skalkotos <skalkoto at grnet.gr>

I've applied this.

I also applied the attached patch, which readds support for the old
format, on the assumption that old FreeBSD guests will still exist for
some time to come.  Hope this is OK.

Thanks,

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
-------------- next part --------------
From 1a4fb80232fe50952e5fcd12f6f823490a624658 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Tue, 5 Nov 2013 11:40:23 +0000
Subject: [PATCH] FreeBSD: Add (back) support for old guests using /dev/adN
 convention.

---
 src/inspect-fs-unix.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 8e0f135..02c744e 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -64,6 +64,7 @@ static pcre *re_major_minor;
 static pcre *re_xdev;
 static pcre *re_cciss;
 static pcre *re_mdN;
+static pcre *re_freebsd_old;
 static pcre *re_freebsd_mbr;
 static pcre *re_freebsd_gpt;
 static pcre *re_diskbyid;
@@ -116,6 +117,7 @@ compile_regexps (void)
   COMPILE (re_xdev, "^/dev/(h|s|v|xv)d([a-z]+)(\\d*)$", 0);
   COMPILE (re_cciss, "^/dev/(cciss/c\\d+d\\d+)(?:p(\\d+))?$", 0);
   COMPILE (re_mdN, "^(/dev/md\\d+)$", 0);
+  COMPILE (re_freebsd_old, "^/dev/ad(\\d+)s(\\d+)([a-z])$", 0);
   COMPILE (re_freebsd_mbr, "^/dev/(ada{0,1}|vtbd)(\\d+)s(\\d+)([a-z])$", 0);
   COMPILE (re_freebsd_gpt, "^/dev/(ada{0,1}|vtbd)(\\d+)p(\\d+)$", 0);
   COMPILE (re_diskbyid, "^/dev/disk/by-id/.*-part(\\d+)$", 0);
@@ -145,6 +147,7 @@ free_regexps (void)
   pcre_free (re_xdev);
   pcre_free (re_cciss);
   pcre_free (re_mdN);
+  pcre_free (re_freebsd_old);
   pcre_free (re_freebsd_mbr);
   pcre_free (re_freebsd_gpt);
   pcre_free (re_diskbyid);
@@ -1503,6 +1506,20 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
       device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
     }
   }
+  else if (match3 (g, spec, re_freebsd_old, &disk, &slice, &part)) {
+    int disk_i = guestfs___parse_unsigned_int (g, disk);
+    int slice_i = guestfs___parse_unsigned_int (g, slice);
+    int part_i = part[0] - 'a' /* counting from 0 */;
+    free (disk);
+    free (slice);
+    free (part);
+
+    if (disk_i != -1 && disk_i <= 26 &&
+        slice_i > 0 && slice_i <= 1 /* > 4 .. see comment above */ &&
+        part_i >= 0 && part_i < 26) {
+      device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
+    }
+  }
   else if ((part = match1 (g, spec, re_diskbyid)) != NULL) {
     r = resolve_fstab_device_diskbyid (g, part, &device);
     free (part);
-- 
1.8.3.1



More information about the Libguestfs mailing list