pyzfs: python3 support (library 2/2)

* 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
This commit is contained in:
Brian Behlendorf 2019-01-04 10:50:04 -08:00
parent 9de8c0cd7f
commit e5fb1dc586
4 changed files with 23 additions and 23 deletions

View 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]))

View 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)

View 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",
}

View 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)