]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Make command line guid parsing more tolerant
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 24 Jan 2014 23:27:59 +0000 (15:27 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 2 Apr 2014 20:10:08 +0000 (13:10 -0700)
Several of the zfs utilities allow you to pass a vdev's guid rather
than the device name.  However, the utilities are not consistent in
how they parse that guid.  For example, 'zinject' expects the guid
to be passed as a hex value while 'zpool replace' wants it as a
decimal.  The user is forced to just know what format to use.

This patch improve things by making the parsing more tolerant.
When strtol(3) is called using 0 for the base, rather than say
10 or 16, it will then accept hex, decimal, or octal input based
on the prefix.  From the man page.

    If base is zero or 16, the string may then include a "0x"
    prefix, and  the number  will  be read in base 16; otherwise,
    a zero base is taken as 10 (decimal) unless the next character
    is '0', in which case it  is  taken as 8 (octal).

NOTE: There may be additional conversions not caught be this patch.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chris Dunlap <cdunlap@llnl.gov>
Issue #2

cmd/zinject/translate.c
lib/libzfs/libzfs_pool.c

index b2ccb673a1936930e5b5528ad1c52bd9bf34a959..5cc9d9fdc7078f7828fbf977cee63005e28564b3 100644 (file)
@@ -467,7 +467,7 @@ translate_device(const char *pool, const char *device, err_type_t label_type,
        if ((zhp = zpool_open(g_zfs, pool)) == NULL)
                return (-1);
 
-       record->zi_guid = strtoull(device, &end, 16);
+       record->zi_guid = strtoull(device, &end, 0);
        if (record->zi_guid == 0 || *end != '\0') {
                tgt = zpool_find_vdev(zhp, device, &isspare, &iscache, NULL);
 
index db1f0d7cf2be398d286edf58d718d90a22c3e801..b1ddd983d89590be062d4e2df097a3248cecc1c8 100644 (file)
@@ -2167,7 +2167,7 @@ zpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare,
 
        verify(nvlist_alloc(&search, NV_UNIQUE_NAME, KM_SLEEP) == 0);
 
-       guid = strtoull(path, &end, 10);
+       guid = strtoull(path, &end, 0);
        if (guid != 0 && *end == '\0') {
                verify(nvlist_add_uint64(search, ZPOOL_CONFIG_GUID, guid) == 0);
        } else if (zpool_vdev_is_interior(path)) {