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