]> git.proxmox.com Git - mirror_zfs.git/commitdiff
pyzfs: python3 support (library 2/2)
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 4 Jan 2019 18:50:04 +0000 (10:50 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Sun, 6 Jan 2019 18:39:41 +0000 (10:39 -0800)
* All pool, dataset, and nvlist keys must be of type bytes.

Reviewed-by: John Ramsden <johnramsden@riseup.net>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
Signed-off-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #8096

contrib/pyzfs/libzfs_core/_error_translation.py
contrib/pyzfs/libzfs_core/_libzfs_core.py
contrib/pyzfs/libzfs_core/_nvlist.py
contrib/pyzfs/libzfs_core/ctypes.py

index 98d3bb22ae5a8209dbb1db85c4e9327ad0cd35a3..b5f4bebce1527ddcaecbe5db16d8d0d77337c624 100644 (file)
@@ -732,7 +732,7 @@ def _pool_name(name):
     '@' separates a snapshot name from the rest of the dataset name.
     '#' separates a bookmark name from the rest of the dataset name.
     '''
-    return re.split('[/@#]', name, 1)[0]
+    return re.split(b'[/@#]', name, 1)[0]
 
 
 def _fs_name(name):
@@ -742,26 +742,26 @@ def _fs_name(name):
     '@' separates a snapshot name from the rest of the dataset name.
     '#' separates a bookmark name from the rest of the dataset name.
     '''
-    return re.split('[@#]', name, 1)[0]
+    return re.split(b'[@#]', name, 1)[0]
 
 
 def _is_valid_name_component(component):
-    allowed = string.ascii_letters + string.digits + '-_.: '
-    return component and all(x in allowed for x in component)
+    allowed = string.ascii_letters + string.digits + u'-_.: '
+    return component and all(x in allowed.encode() for x in component)
 
 
 def _is_valid_fs_name(name):
-    return name and all(_is_valid_name_component(c) for c in name.split('/'))
+    return name and all(_is_valid_name_component(c) for c in name.split(b'/'))
 
 
 def _is_valid_snap_name(name):
-    parts = name.split('@')
+    parts = name.split(b'@')
     return (len(parts) == 2 and _is_valid_fs_name(parts[0]) and
             _is_valid_name_component(parts[1]))
 
 
 def _is_valid_bmark_name(name):
-    parts = name.split('#')
+    parts = name.split(b'#')
     return (len(parts) == 2 and _is_valid_fs_name(parts[0]) and
             _is_valid_name_component(parts[1]))
 
index aa387dbb3cabfa189ee55738c0bf1a1523e22e18..589926ba876fe584332cd59fc1c75ba53307d4d9 100644 (file)
@@ -113,7 +113,7 @@ def lzc_create(name, ds_type='zfs', props=None, key=None):
     if props is None:
         props = {}
     if key is None:
-        key = bytes("")
+        key = b""
     else:
         key = bytes(key)
     if ds_type == 'zfs':
@@ -848,7 +848,7 @@ def lzc_change_key(fsname, crypt_cmd, props=None, key=None):
     if props is None:
         props = {}
     if key is None:
-        key = bytes("")
+        key = b""
     else:
         key = bytes(key)
     cmd = {
@@ -931,13 +931,13 @@ def lzc_channel_program(
         error.
     '''
     output = {}
-    params_nv = nvlist_in({"argv": params})
+    params_nv = nvlist_in({b"argv": params})
     with nvlist_out(output) as outnvl:
         ret = _lib.lzc_channel_program(
             poolname, program, instrlimit, memlimit, params_nv, outnvl)
     errors.lzc_channel_program_translate_error(
-        ret, poolname, output.get("error"))
-    return output.get("return")
+        ret, poolname, output.get(b"error"))
+    return output.get(b"return")
 
 
 def lzc_channel_program_nosync(
@@ -976,13 +976,13 @@ def lzc_channel_program_nosync(
         error.
     '''
     output = {}
-    params_nv = nvlist_in({"argv": params})
+    params_nv = nvlist_in({b"argv": params})
     with nvlist_out(output) as outnvl:
         ret = _lib.lzc_channel_program_nosync(
             poolname, program, instrlimit, memlimit, params_nv, outnvl)
     errors.lzc_channel_program_translate_error(
-        ret, poolname, output.get("error"))
-    return output.get("return")
+        ret, poolname, output.get(b"error"))
+    return output.get(b"return")
 
 
 def lzc_receive_resumable(
@@ -1406,7 +1406,7 @@ def lzc_receive_with_cmdprops(
     if cmdprops is None:
         cmdprops = {}
     if key is None:
-        key = bytes("")
+        key = b""
     else:
         key = bytes(key)
 
@@ -1511,7 +1511,7 @@ def lzc_sync(poolname, force=False):
         `innvl` has been replaced by the `force` boolean and `outnvl` has been
         conveniently removed since it's not used.
     '''
-    innvl = nvlist_in({"force": force})
+    innvl = nvlist_in({b"force": force})
     with nvlist_out({}) as outnvl:
         ret = _lib.lzc_sync(poolname, innvl, outnvl)
     errors.lzc_sync_translate_error(ret, poolname)
index d7451bfe3967683ccd5d6cab1237d2660a517239..fe4239a3c06ecc103b83e0bd4a584d6e75c1eb7f 100644 (file)
@@ -160,10 +160,10 @@ def _type_info(typeid):
 
 # only integer properties need to be here
 _prop_name_to_type_str = {
-    "rewind-request":   "uint32",
-    "type":             "uint32",
-    "N_MORE_ERRORS":    "int32",
-    "pool_context":     "int32",
+    b"rewind-request":   "uint32",
+    b"type":             "uint32",
+    b"N_MORE_ERRORS":    "int32",
+    b"pool_context":     "int32",
 }
 
 
index eab1602196d64ceddaca66ad2f0bdf2f006e067d..d337f46ed64382533235e3faca8834aaa61e01a1 100644 (file)
@@ -31,8 +31,8 @@ def _ffi_cast(type_name):
             try:
                 type_info.elements[value]
             except KeyError as e:
-                raise OverflowError('Invalid enum <%s> value %s' %
-                                    (type_info.cname, e.message))
+                raise OverflowError('Invalid enum <%s> value %s: %s' %
+                                    (type_info.cname, value, e))
         else:
             _ffi.new(type_name + '*', value)
         return _ffi.cast(type_name, value)