Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08F331D5141 for ; Fri, 27 Mar 2026 04:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774585119; cv=none; b=dTFn2a5q4netaMDknsXuHdURYMiIwWy7QgVS0NK1grNviszyzHNIX+4SML4udpYxV+Efz8JU7yYwf0AQLN823XivOWmq+AIwDCwZxcXLI/1RNCOHdARQZH2I3MrZhOZXDOwMAaDXeI1nml3Zn3OHRgAtSf0Q/oK7KaKUmvTxPnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774585119; c=relaxed/simple; bh=FzAWLsRlwYVL7YjOsWY2GC1L51DnmZAn7nsa5sJ/7Vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LYWaP/mvznqBocpLtaS8tMrWIaKNJIMwD7Pp/XhZcMxaaokoyi+n3p54YknQfvjZMy/U/VkbRpnhyY7oRR3xZdpQNcRZ5QCYv5zL+cy5i3JE6FBT0YHDJ1v2OQ/hVOewPsCGuou7vDpkci8teKuZwL8pvuE7uSsHN8bp4fRtRWM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ovzgss4g; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ovzgss4g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774585117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W3aU4qk83kl6kkOLpCovHMlXdTf9VagVYyyJQWy3LuA=; b=Ovzgss4gOZz3v4zlFv/Zo+CJjgoq4nkINV7WTFfWnS3wWUleQDUTy1t5jwGONVVENd/LOK g5qaOkOo0YMpbGyqwy62HOHUc1vkw9t5AlXMBrR8LTKP0tesLrypXCDn9tSuykx1zEvcZF Lep7jeQ4NKvMHaC5ZIrm6ZxJ11Ol2S0= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-170-ppP6Pis_NXqRNma2H9Bvmg-1; Fri, 27 Mar 2026 00:18:33 -0400 X-MC-Unique: ppP6Pis_NXqRNma2H9Bvmg-1 X-Mimecast-MFC-AGG-ID: ppP6Pis_NXqRNma2H9Bvmg_1774585112 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A4731800345; Fri, 27 Mar 2026 04:18:32 +0000 (UTC) Received: from localhost (dell-per660-10.rhts.eng.pek2.redhat.com [10.73.4.30]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 82EDD18002A6; Fri, 27 Mar 2026 04:18:31 +0000 (UTC) From: Jianhong Yin To: linux-nfs@vger.kernel.org Cc: calum.mackay@oracle.com, jlayton@kernel.org, bcodding@redhat.com, smayhew@redhat.com, jiyin@redhat.com Subject: [PATCH 3/4] pynfs: fix nfs4.1/nfs4server.py error with python3.12+ Date: Fri, 27 Mar 2026 12:16:20 +0800 Message-ID: <20260327041620.2115456-4-jiyin@redhat.com> In-Reply-To: <20260327041620.2115456-2-jiyin@redhat.com> References: <20260327041620.2115456-2-jiyin@redhat.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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 Signed-off-by: Jianhong Yin --- nfs4.1/fs.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/nfs4.1/fs.py b/nfs4.1/fs.py index 305326b..c5b1d2d 100644 --- a/nfs4.1/fs.py +++ b/nfs4.1/fs.py @@ -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)") -- 2.53.0