pynfs: nfs4.1/nfs4server.py fixes
Subsystems (2)
PATCH 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()
Signed-off-by Scott Mayhew <[email protected]>
--- 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