pynfs: nfs4.1/nfs4server.py fixes
Subsystems (2)
PATCH v3 1/4 pynfs: nfs4.1/nfs4server.py fixes
From: Scott Mayhew <[email protected]>
Most of the strings in pynfs are not str but rather "bytes" objects.
- fixed default string type
- "string" -> b"string"
- .encode("utf-8")
- StringIO -> BytesIO
- etc
- nfsstat4 -> const4.nfsstat4
- python3: fixed syntax of Exception process code
- python3: d.itervalues() -> d.values()
--- nfs4.1/config.py | 20 ++++---- nfs4.1/dataserver.py | 32 ++++++------- nfs4.1/fs.py | 52 +++++++++++--------- nfs4.1/nfs4client.py | 4 +- nfs4.1/nfs4server.py | 81 +++++++++++++++++--------------- nfs4.1/nfs4state.py | 46 +++++++++--------- nfs4.1/sample_code/ds_exports.py | 2 +- nfs4.1/server_exports.py | 12 ++--- 8 files changed, 129 insertions(+), 120 deletions(-)
nfs4.1/config.py +8 -12
@@ -117,8 +117,7 @@ class MetaConfig(type): setattr(cls, attr.name, property(make_get(i), make_set(i), None, attr.comment)) -class ServerConfig(object): - __metaclass__ = MetaConfig +class ServerConfig(metaclass=MetaConfig): attrs = [ConfigLine("allow_null_data", False, "Server allows NULL calls to contain data"), ConfigLine("tag_info", True,
@@ -131,17 +130,16 @@ class ServerConfig(object): def __init__(self): self.minor_id = os.getpid() - self.major_id = "PyNFSv4.1" + self.major_id = b"PyNFSv4.1" self._owner = server_owner4(self.minor_id, self.major_id) - self.scope = "Default_Scope" - self.impl_domain = "citi.umich.edu" - self.impl_name = "pynfs X.X" + self.scope = b"Default_Scope" + self.impl_domain = b"citi.umich.edu" + self.impl_name = b"pynfs X.X" self.impl_date = 1172852767 # int(time.time()) self.impl_id = nfs_impl_id4(self.impl_domain, self.impl_name, nfs4lib.get_nfstime(self.impl_date)) -class ServerPerClientConfig(object): - __metaclass__ = MetaConfig +class ServerPerClientConfig(metaclass=MetaConfig): attrs = [ConfigLine("maxrequestsize", 16384, "Maximum request size the server will accept"), ConfigLine("maxresponsesize", 16384,
@@ -175,15 +173,13 @@ _invalid_ops = [ OP_RELEASE_LOCKOWNER, OP_ILLEGAL, ] -class OpsConfigServer(object): - __metaclass__ = MetaConfig +class OpsConfigServer(metaclass=MetaConfig): value = ['ERROR', 0, 0] # Note must have value == _opline(value) attrs = (lambda value=value: [ConfigLine(name.lower()[3:], value, "Generic comment", _opline) for name in nfs_opnum4.values()])() -class Actions(object): - __metaclass__ = MetaConfig +class Actions(metaclass=MetaConfig): attrs = [ConfigLine("reboot", 0, "Any write here will simulate a server reboot", _action),
nfs4.1/dataserver.py +16 -16
@@ -59,27 +59,27 @@ class DataServer(object): def get_netaddr4(self): # STUB server multipathing not supported yet - uaddr = '.'.join([self.server, - str(self.port >> 8), - str(self.port & 0xff)]) - return type4.netaddr4(self.proto, uaddr) + uaddr = b'.'.join([self.server.encode("utf-8"), + str(self.port >> 8).encode("utf-8"), + str(self.port & 0xff).encode("utf-8")]) + return type4.netaddr4(self.proto.encode("utf-8"), uaddr) def get_multipath_netaddr4s(self): netaddr4s = [] for addr in self.multipath_servers: server, port = addr - uaddr = '.'.join([server, - str(port >> 8), - str(port & 0xff)]) - proto = "tcp" + uaddr = b'.'.join([server.encode("utf-8"), + str(port >> 8).encode("utf-8"), + str(port & 0xff).encode("utf-8")]) + proto = b"tcp" if server.find(':') >= 0: - proto = "tcp6" + proto = b"tcp6" netaddr4s.append(type4.netaddr4(proto, uaddr)) return netaddr4s def fh_to_name(self, mds_fh): - return hashlib.sha1("%r" % mds_fh).hexdigest() + return hashlib.sha1(mds_fh).hexdigest() def connect(self): raise NotImplemented
@@ -111,7 +111,7 @@ class DataServer41(DataServer): self.reset() else: log.error("Unhandled status %s from DS %s" % - (nfsstat4[res.status], self.server)) + (const4.nfsstat4[res.status], self.server)) raise Exception("Dataserver communication error") def connect(self):
@@ -122,7 +122,7 @@ class DataServer41(DataServer): summary=self.summary) self.c1.set_cred(self.cred1) self.c1.null() - c = self.c1.new_client("DS.init_%s" % self.server) + c = self.c1.new_client(b"DS.init_%s" % self.server.encode("utf-8")) # This is a hack to ensure MDS/DS communication path is at least # as wide as the client/MDS channel (at least for linux client) fore_attrs = type4.channel_attrs4(0, 16384, 16384, 2868, 8, 8, [])
@@ -154,11 +154,11 @@ class DataServer41(DataServer): access = const4.OPEN4_SHARE_ACCESS_BOTH deny = const4.OPEN4_SHARE_DENY_NONE attrs = {const4.FATTR4_MODE: 0o777} - owner = "mds" + owner = b"mds" mode = const4.GUARDED4 verifier = self.sess.c.verifier openflag = type4.openflag4(const4.OPEN4_CREATE, type4.createhow4(mode, attrs, verifier)) - name = self.fh_to_name(mds_fh) + name = self.fh_to_name(mds_fh).encode("utf-8") while True: if mds_fh in self.filehandles: return
@@ -338,14 +338,14 @@ class DSDevice(object): server_list = server_list[:-1] try: log.info("Adding dataserver ip:%s port:%s path:%s" % - (server, port, '/'.join(path))) + (server, port, b'/'.join(path))) ds = DataServer41(server, port, path, mdsds=self.mdsds, multipath_servers=server_list, summary=server_obj.summary) self.list.append(ds) except socket.error: log.critical("cannot access %s:%i/%s" % - (server, port, '/'.join(path))) + (server, port, b'/'.join(path))) sys.exit(1) self.active = 1 self.address_body = self._get_address_body()
nfs4.1/fs.py +29 -23
158 lines not on this page · raw message
nfs4.1/nfs4client.py +2 -2
@@ -183,7 +183,7 @@ class NFS4Client(rpc.Client, rpc.Server): return env try: self.check_utf8str_cs(args.tag) - except NFS4Errror as e: + except NFS4Error as e: env.results.set_empty_return(e.status, "Invalid utf8 tag") return env # Handle the individual operations
@@ -211,7 +211,7 @@ class NFS4Client(rpc.Client, rpc.Server): except NFS4Replay: # Just pass this on up raise - except Exception: + except StandardError: # Uh-oh. This is a server bug traceback.print_exc() result = encode_status_by_name(opname.lower()[3:],
nfs4.1/nfs4server.py +44 -37
267 lines not on this page · raw message
nfs4.1/nfs4state.py +23 -23
125 lines not on this page · raw message
nfs4.1/sample_code/ds_exports.py +1 -1
@@ -6,4 +6,4 @@ from fs import StubFS_Mem def mount_stuff(server, opts): B = StubFS_Mem(2) - server.mount(B, path="/pynfs_mds") + server.mount(B, path=b"/pynfs_mds")
nfs4.1/server_exports.py +6 -6
@@ -4,22 +4,22 @@ from dataserver import DSDevice def mount_stuff(server, opts): """Mount some filesystems to the server""" # STUB - just testing stuff out - A = StubFS_Disk("/tmp/py41/fs1", opts.reset, 1) + A = StubFS_Disk(b"/tmp/py41/fs1", opts.reset, 1) B = StubFS_Mem(2) C = StubFS_Mem(3) - server.mount(A, path="/a") - server.mount(B, path="/b") - server.mount(C, path="/foo/bar/c") + server.mount(A, path=b"/a") + server.mount(B, path=b"/b") + server.mount(C, path=b"/foo/bar/c") if opts.use_block: dev = _create_simple_block_dev() E = BlockLayoutFS(5, backing_device=dev) - server.mount(E, path="/block") + server.mount(E, path=b"/block") if opts.use_files: dservers = _load_dataservers(opts.dataservers, server) if dservers is None: return F = FileLayoutFS(6, dservers) - server.mount(F, path="/files") + server.mount(F, path=b"/files") def _create_simple_block_dev(): from block import Simple, Slice, Concat, Stripe, BlockVolume
Signature · 1 line
2.53.0
PATCH v3 2/4 pynfs: fix nfs4.1/nfs4server.py error with python3.12+
force use gdbm as the backend of shelve module, to avoid error:
'''
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. '''
test pass on RHEL-9 RHEL-10 and Fedora-43
--- nfs4.1/fs.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
nfs4.1/fs.py +16 -4
@@ -932,9 +932,11 @@ class ConfigFS(FileSystem): ################################################### import os +import sys import pickle import shutil import shelve +import dbm.gnu as gdbm class StubFS_Disk(FileSystem): _fs_data_name = b"fs_info" # DB name where we store persistent data
@@ -948,6 +950,16 @@ class StubFS_Disk(FileSystem): self._init(path) # XXX Note shelve DB is still open + def _dbpath(self, path): + """ + generate proper dbpath format according python version. + see: https://docs.python.org/3.13/library/dbm.html#module-dbm.gnu + """ + dbpath = os.path.join(path, self._fs_data_name) + if sys.version_info < (3, 11): + dbpath = dbpath.decode("utf-8") + return dbpath + def _reset(self, path, fsid): """Create an empty fs, overwriting all existing data.""" # Check path exists
@@ -959,8 +971,8 @@ class StubFS_Disk(FileSystem): shutil.rmtree(path) os.makedirs(path) # This needs to be open before calling __init__ - d = self._fs_data = shelve.open(os.path.join(path, self._fs_data_name), - "n") + db = gdbm.open(self._dbpath(path), "n") + d = self._fs_data = shelve.Shelf(db) d["_nextid"] = self._nextid # normal __init__ FileSystem.__init__(self)
@@ -980,8 +992,8 @@ class StubFS_Disk(FileSystem): if not os.path.isdir(path): raise RuntimeError("Path doesn't exist, try using '--reset' option") # Ensure persistent fs data exists there - d = self._fs_data = shelve.open(os.path.join(path, self._fs_data_name), - "w") # w needed for later allocation + db = gdbm.open(self._dbpath(path), "w") # w needed for later allocation + d = self._fs_data = shelve.Shelf(db) # Do __init__ portion that is needed self.objclass = FSObject self._disk_lock = Lock("FSLock(Disk)")
Signature · 1 line
2.53.0
PATCH v3 3/4 pynfs: nfs4.1/nfs4server.py allow v4.2 mount
In reply to Jianhong Yin--- nfs4.1/nfs4server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nfs4.1/nfs4server.py +1 -1
@@ -578,7 +578,7 @@ class NFS4Server(rpc.Server): self._fsids = {self.root.fs.fsid: self.root.fs} # {fsid: fs} self.clients = ClientList() # List of attached clients self.sessions = {} # List of attached sessions - self.minor_versions = [1] + self.minor_versions = [1, 2] self.config = ServerConfig() self.opsconfig = OpsConfigServer() self.actions = Actions()
Signature · 1 line
2.53.0
PATCH v3 4/4 pynfs: fix various types of errors in nfs4.1/nfs4proxy.py
In reply to Jianhong YinMost of the strings in pynfs are not str but rather "bytes" objects.
- "string" -> b"string"
- python3: is -> '=='
test pass on RHEL-9, RHEL-10,Fedora-43
--- nfs4.1/nfs4proxy.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
nfs4.1/nfs4proxy.py +8 -8
@@ -46,7 +46,7 @@ class NFS4Proxy(rpc.Server): self.cb_versions = [cb_version] # currently support only root (? fix ? ) rpcsec = rpc.security.instance(rpc.AUTH_SYS) - self.default_cred = rpcsec.init_cred(uid=0,gid=0,name="root") + self.default_cred = rpcsec.init_cred(uid=0,gid=0,name=b"root") if pipe: #reuse connection self.pipe = pipe else:
@@ -60,7 +60,7 @@ class NFS4Proxy(rpc.Server): return (min(self.cb_versions), max(self.cb_versions)) def _find_method(self, msg): - method = getattr(self.proxy, 'handle_cb_%i' % msg.proc, None) + method = getattr(self.proxy, b'handle_cb_%i' % msg.proc, None) if method is not None: return method return None
@@ -162,8 +162,8 @@ class NFS4Proxy(rpc.Server): log.debug("** CALLBACK **") log.debug("Handling NULL") try: - self.forward_call(calldata="", callback=callback, procedure=0) - return rpc.SUCCESS, '' + self.forward_call(calldata=b"", callback=callback, procedure=0) + return rpc.SUCCESS, b'' except rpc.RPCTimeout: log.critical("Error: cannot connect to destination server") return rpc.GARBAGE_ARGS, None
@@ -192,7 +192,7 @@ class NFS4Proxy(rpc.Server): env = CompoundState(args, cred) for arg in args.argarray: env.index += 1 - opname = nfs_opnum4.get(arg.argop, 'op_illegal') + opname = nfs_opnum4.get(arg.argop, b'op_illegal') log.info("*** %s (%d) ***" % (opname, arg.argop)) # look for functions implemented by the proxy # that override communication
@@ -210,7 +210,7 @@ class NFS4Proxy(rpc.Server): if error is not None: result = encode_status_by_name(opname.lower()[3:], int(error), - msg="Proxy Rewrite Error") + msg=b"Proxy Rewrite Error") env.results.append(result) p = nfs4lib.FancyNFS4Packer() if callback:
@@ -288,7 +288,7 @@ class NFS4Proxy(rpc.Server): attrs.ca_maxoperations = chan.maxoperations if chan.maxrequests < attrs.ca_maxrequests: attrs.ca_maxrequests = chan.maxrequests - if direction is 0: # client to proxy + if direction == 0: # client to proxy # XXX: this might be buggy with more than one clients (?) self.start_cb_proxy(arg.opcreate_session.csa_cb_program, version=1, client_pipe=cred.connection)
@@ -296,7 +296,7 @@ class NFS4Proxy(rpc.Server): self.fchannel) _adjust_channel_values(arg.opcreate_session.csa_back_chan_attrs, self.bchannel) - elif direction is 1: # proxy to client + elif direction == 1: # proxy to client pass #FUNCTION OVERRIDING END
Signature · 1 line
2.53.0