From nobody Sat Apr 4 00:25:10 2026 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CF1D33D511 for ; Sat, 21 Mar 2026 17:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774115893; cv=none; b=mFGW3KhhH2MYMfYL6oxc9NfGQGZV2VDo551nYXVPBHKTiVm5Sj/EIqpbIBq0WXN71bCvvML1UOeoAJA0UTF0eSuwhYAzHe03Q0CSMZCAhxg+9J74aVypnnmmcb/mMyOMqq1paPf+yBk60ZFmrA0gTgn+M1gi8+RP/Dp64A3v2CU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774115893; c=relaxed/simple; bh=czt3DDK3Q9LMgggKCBsqxDSoXwaqrRNd+/LUBmGAS7M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cE+v5+SDxHHfz5QQcL2/PPya/3vDB78LA0ON9ITdBl1W8H/y/fHEHFlSLaHslv3xdUy9VWNxZ0jDNxE1RgozSXFFPGz5diYRsttKOjp2xZZdD4O2sxoMI+XjKacjASsZEJptp25OnddroftTExTKr6qtX0kMH3P3h4q7KOkGpeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=eeH2h1Jk; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="eeH2h1Jk" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-8cb3bae8d3eso269632185a.1 for ; Sat, 21 Mar 2026 10:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774115891; x=1774720691; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GBOfKv8+dSxaoWkBve3vKf+AERqgheSr1LH0+CQ4vtE=; b=eeH2h1JkCzGMbUaQ6P87k/z8iP+HDN1iG2Z74LGdO8E5oVf9yolKGANZFyTtwR1aIC Cql1PK8aHYfroynH1QaF6ZIGXG9a97+/tM3lfek+WQ8/ZEp1HSZxlJogqIVkAZdLnq3K V853lErWJV6HGhS3Bk6OJ7cUipTVIbJDaW+iDgE2ExMR9TE0JC3hte69EtnNLuDyif5z xiI2QkYsbtZ0F5Tm22OEHrxCaewFdDSjvZUpqAOY0H1aAzX6w0ag3tLb7otpQG1AuUWL etjb8uAMGB7heeuXMhtSLzbhnyoDoUMvgqok1N7kXdk+Vvzbvz/AfwDvSvmNVYny5hIr e9Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774115891; x=1774720691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=GBOfKv8+dSxaoWkBve3vKf+AERqgheSr1LH0+CQ4vtE=; b=OsblIfjE0ceR/Qiq0ddyx+8EZkQ/kB1H2pdv/AbdQqUtOpEg2Z2pP31Uba+KlVvDFq V7JGmUt5svdGNACslQCefAORh4+WiLPeQoYxLAiIkpnYv/+y+5Y6kEaJLj/yH2/18oCE +00RG8tpNvNkZSvwn1Ac4WMOozSycd7qAUwaEvHuK2SKQjdkfppL2VbkiTEdexm1wtAV bQx//0lVSWnneApac4AkBRrvtU1IwChxd6Cw7Ml1eszGtlsM8WGf4z7CiMy4dKCZrQkO bS2mua+TieP+DXunREHDKcODSIRdmAzs9dbzeWJ9/P60XnLfXxdEMG/MP2Hz2bzttfKp jqQg== X-Forwarded-Encrypted: i=1; AJvYcCUpAIuszPTpsXrtrFWwJ6LfRYJEOE23IUFO2ZXJTgLX1Y8N0m7b+s5uKdlvVi78DOyZQ7Hrol7PvqgabWw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywwki/E2sa8pNL336ObzAZ52HdNxYOjnX6AuVD55kPC+HN9f+wz a6hQ6WGkYlI4roJngCyXxGWWeBGbopMEooKE/YxCL9hrUqCtFk5TnvypyuUzhlx0opg= X-Gm-Gg: ATEYQzyHEZT6iHcsrorYA9kmsRZ7JaYZQMI8aAV3QxG9W7Vo3MDbSsw9MbJAQgf302X j3dPoXy0XPCLHdkhFww3/ZrcRzKT9ZCu3IWR4IYr2MY75klcxT+x40Jlh5RDKRu5vxbDH9iva31 LprhyWFKDNfMYQdu22SJgFo7vy5UaTMkehIekolqmeSt7pXg2S2CU1VyfNjy8fTvIIWsSj//jHP ne64bKQ17tjiqoypPoXVw0aP42tpUcJsuAkQ+6pZBoPOvizJAQwsT+YVLKAs5FsY0HF5qXMt3Y/ gdoPWfWF2jkojnAhCuyaC2zWCJTWWCFnpJgjdO7cB4UdPAN6lDv/vrfJr0/jGqfFpftLTr/H8b2 AdE7Ml8C9nJXHf8u9g0CZpIV/hAGtcQo1XvEBq/hgcDjzAZPsf1rELVwJ63juzbDyBR4tVEqemK XwbK4KJYYDGEi5sNLJaVANVP1/cyREttiXnQGtWdNHjqJ0ZTfIUv//gwMDSpIY3jgo+Fp57leUH JJY X-Received: by 2002:a05:620a:170f:b0:8cd:d921:7075 with SMTP id af79cd13be357-8cfc7f8adabmr1070366885a.71.1774115891450; Sat, 21 Mar 2026 10:58:11 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cfc9089ca9sm426515985a.24.2026.03.21.10.58.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2026 10:58:11 -0700 (PDT) From: Pasha Tatashin To: brauner@kernel.org, linux-kselftest@vger.kernel.org, rppt@kernel.org, jack@suse.cz, shuah@kernel.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH 1/2] liveupdate: prevent double management of files Date: Sat, 21 Mar 2026 17:58:07 +0000 Message-ID: <20260321175808.57942-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260321175808.57942-1-pasha.tatashin@soleen.com> References: <20260321175808.57942-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, LUO does not prevent the same file from being managed twice across different active sessions. Add a new i_state flag I_LUO_MANAGED and update luo_preserve_file() to check and set this flag when a file is preserved, and clear it in luo_file_unpreserve_files() when it is released. Additionally, set this flag in luo_retrieve_file() after a file is successfully restored in the new kernel, and clear it in luo_file_finish() when the LUO session is finalized. This ensures that the same file (inode) cannot be managed by multiple sessions. If another session attempts to preserve an already managed file, it will now fail with -EBUSY. Acked-by: Pratyush Yadav (Google) Acked-by: Jan Kara Signed-off-by: Pasha Tatashin --- include/linux/fs.h | 5 ++++- kernel/liveupdate/luo_file.c | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 23f36a2613a3..692a8be56f3c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -712,6 +712,8 @@ is_uncached_acl(struct posix_acl *acl) * I_LRU_ISOLATING Inode is pinned being isolated from LRU without holding * i_count. * + * I_LUO_MANAGED Inode is being managed by a live update session. + * * Q: What is the difference between I_WILL_FREE and I_FREEING? * * __I_{SYNC,NEW,LRU_ISOLATING} are used to derive unique addresses to wait @@ -744,7 +746,8 @@ enum inode_state_flags_enum { I_CREATING =3D (1U << 15), I_DONTCACHE =3D (1U << 16), I_SYNC_QUEUED =3D (1U << 17), - I_PINNING_NETFS_WB =3D (1U << 18) + I_PINNING_NETFS_WB =3D (1U << 18), + I_LUO_MANAGED =3D (1U << 19), }; =20 #define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 5acee4174bf0..86911beeff71 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -248,6 +248,7 @@ static bool luo_token_is_used(struct luo_file_set *file= _set, u64 token) * Context: Can be called from an ioctl handler during normal system opera= tion. * Return: 0 on success. Returns a negative errno on failure: * -EEXIST if the token is already used. + * -EBUSY if the file descriptor is already preserved by another s= ession. * -EBADF if the file descriptor is invalid. * -ENOSPC if the file_set is full. * -ENOENT if no compatible handler is found. @@ -276,6 +277,14 @@ int luo_preserve_file(struct luo_file_set *file_set, u= 64 token, int fd) if (err) goto err_fput; =20 + scoped_guard(spinlock, &file_inode(file)->i_lock) { + if (inode_state_read(file_inode(file)) & I_LUO_MANAGED) { + err =3D -EBUSY; + goto err_free_files_mem; + } + inode_state_set(file_inode(file), I_LUO_MANAGED); + } + err =3D -ENOENT; list_private_for_each_entry(fh, &luo_file_handler_list, list) { if (fh->ops->can_preserve(fh, file)) { @@ -286,11 +295,11 @@ int luo_preserve_file(struct luo_file_set *file_set, = u64 token, int fd) =20 /* err is still -ENOENT if no handler was found */ if (err) - goto err_free_files_mem; + goto err_unpreserve_inode; =20 err =3D luo_flb_file_preserve(fh); if (err) - goto err_free_files_mem; + goto err_unpreserve_inode; =20 luo_file =3D kzalloc_obj(*luo_file); if (!luo_file) { @@ -320,6 +329,9 @@ int luo_preserve_file(struct luo_file_set *file_set, u6= 4 token, int fd) kfree(luo_file); err_flb_unpreserve: luo_flb_file_unpreserve(fh); +err_unpreserve_inode: + scoped_guard(spinlock, &file_inode(file)->i_lock) + inode_state_clear(file_inode(file), I_LUO_MANAGED); err_free_files_mem: luo_free_files_mem(file_set); err_fput: @@ -363,6 +375,9 @@ void luo_file_unpreserve_files(struct luo_file_set *fil= e_set) luo_file->fh->ops->unpreserve(&args); luo_flb_file_unpreserve(luo_file->fh); =20 + scoped_guard(spinlock, &file_inode(luo_file->file)->i_lock) + inode_state_clear(file_inode(luo_file->file), I_LUO_MANAGED); + list_del(&luo_file->list); file_set->count--; =20 @@ -609,6 +624,9 @@ int luo_retrieve_file(struct luo_file_set *file_set, u6= 4 token, *filep =3D luo_file->file; luo_file->retrieve_status =3D 1; =20 + scoped_guard(spinlock, &file_inode(luo_file->file)->i_lock) + inode_state_set(file_inode(luo_file->file), I_LUO_MANAGED); + return 0; } =20 @@ -701,8 +719,11 @@ int luo_file_finish(struct luo_file_set *file_set) =20 luo_file_finish_one(file_set, luo_file); =20 - if (luo_file->file) + if (luo_file->file) { + scoped_guard(spinlock, &file_inode(luo_file->file)->i_lock) + inode_state_clear(file_inode(luo_file->file), I_LUO_MANAGED); fput(luo_file->file); + } list_del(&luo_file->list); file_set->count--; mutex_destroy(&luo_file->mutex); --=20 2.43.0 From nobody Sat Apr 4 00:25:10 2026 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76F4734751E for ; Sat, 21 Mar 2026 17:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774115895; cv=none; b=s/H/nojWmUml00GjWGV/Tt8A1CECB7MqpOpJRjhCrJTPhJjb7btUuTAGE179FodeO21TGlwLDAU9mlEIBreEr44WEdeXGO/jc30SA5QCKIGesC9NOol9AvRi2Rb7NevisgGWwHlOt3bbs4P3HRjq+mqOgG7kuOoIl496mFGMIqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774115895; c=relaxed/simple; bh=LI3SMXsnBn5nSeznTWFsUVVpxVDKbB9pJnDUUCkPN10=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mUabq3FcwV0/r+5/L7GWL8aHV3MLJbEWIhTDZCZ+K6PN5XJlPXa/t/2b9YDde2jA2vnHbrnZR8l0zVFpJDQvznSHs74AiZJHeIFw2rvyTYwiPadjWHeSIboriIGUWLuep7xG1aOJH/QseUmQEdDK6PpotiJU0eGdqAf7LaeleD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=Dz+r8qj7; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="Dz+r8qj7" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-8cb38e86cf2so276266185a.1 for ; Sat, 21 Mar 2026 10:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774115893; x=1774720693; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ob8Y//wo6MRj/M0Dz67mgrBX7aDHTN1F2suUDWyFSyU=; b=Dz+r8qj7MM/VFJu+GfI+Ha9dNj+jry+e9m7vzd1y4ZgEEqbSWeqS6cVq1orp5u+efD 8Zv42dZDNsvF2Ej6rJnPULMJgCKVqwNSMZa1B9E3EyMIUEqrz+v8MeuFmJxCtH/x1ny3 w62Dte4tlaW2+j+Qk5wPWS3AEjbZMnJROiB2BkxKGp/UkVclDOdPodfHQ5ah7rRRGyxY yrgMfUHAd4Ii+pTMg/lkNe+PGpJwOhPGGMBgkdYHbH5MECgWW2jlR2THUJwZYJyKQhlL 8RqgUfaEHfXgOUyrZ8GQuFAPqmTpBw6FiP9rp8xhnxWRWZzXJn1bRmFuJBs8g8HTJd12 S94g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774115893; x=1774720693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ob8Y//wo6MRj/M0Dz67mgrBX7aDHTN1F2suUDWyFSyU=; b=GmvYy04c9rKB3Z2JXGbuY1xfuw11NJBUpn7rFdeAgg9VeHbQJDrmOUb458tjbeJFpx 8Ebolc1oUIqfhHS/z4wR5m13Cd5joIWXc9oitWCGCmPQKuwmpnb6K4wgrUMk0x+7XCga xWXezsJkWIhCItl5h6OQJIHocXHc2f6Qr6M4V6i+e3t/FgrgU7+af8gM4JFLEGR/80j2 /bb3Jq07OFgC8H/tWmzEjCF+yYiR6GQvvGcINywbz8s+RD0eBbZDFnmtB741lxxJe3CZ hXqZlwyZRvYxAw2tPwjVK+fQsmR7jTOatBVz/bY3liVOqUbQMcey17lGoQsV46UrYDqc UAIg== X-Forwarded-Encrypted: i=1; AJvYcCVoXVrkvZmmF0OVrKiiV1rC4l+tNS8ml/28uSMBChwcM+KkG3W62dWIxLhnLoG6kOeHErw0SWriQdEaI/A=@vger.kernel.org X-Gm-Message-State: AOJu0YyNM/E8+hf6p0AY65bg7yPJA+NULWorTgW6Smy3epND/qeNH+ii Ye+UQM1NovnjuvMiW45W0Eez2URxdPEahYA/JY+yoHn2dsWurPi1nzCiNu1pgnDDfPc= X-Gm-Gg: ATEYQzzM/FWhQNwDRb0JzrIQ9Y+VaE8HIkxrfvDNKxrBdaP/4hDdiLW/mKY7L5cClbk EAhwb5IkTS1aNJm/5WGA7PVfHhFUPAK0nYEB8lPRGe9oENBIrhM4HRhiVZPgKn9znmCQUj7j/QX bSYJSirOe3eCxCmzWsSQCfVckDqDtTnVlZJW+Zbrr2dCqbVeOFOKwP2EtfYs5YC21NN57D65If0 UOk4qI4Qul8VRh0ko84gdrony6Ydkdye+mbZ7iCMsO6X9IqlAMWR5jgYN7VKPIQEWeixm+E3YVn cW+xUUIIbhlro01jkzE7t6SIWCp7TdVsdSujds/2FOK2OFgam2NCqGX0pLBSjiNXAQiWWrjpw96 OuS44JnsQ0ehFQmegfj6ds+XOapX2p7qXHU+9VfxkO9TzSaCYx+8SQKQL8xx383vDf/Fo5+K7AO cXnUCMUiIEEModVd+E0J+zXye++Ov51rimXxZLd8H8bRSa/RvLkbaUVrfujcwZhtZYhw== X-Received: by 2002:a05:620a:aa03:b0:8cf:cf2c:e021 with SMTP id af79cd13be357-8cfcf2ce4d1mr751287185a.7.1774115893390; Sat, 21 Mar 2026 10:58:13 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cfc9089ca9sm426515985a.24.2026.03.21.10.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2026 10:58:12 -0700 (PDT) From: Pasha Tatashin To: brauner@kernel.org, linux-kselftest@vger.kernel.org, rppt@kernel.org, jack@suse.cz, shuah@kernel.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH 2/2] selftests: liveupdate: add test for double preservation Date: Sat, 21 Mar 2026 17:58:08 +0000 Message-ID: <20260321175808.57942-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260321175808.57942-1-pasha.tatashin@soleen.com> References: <20260321175808.57942-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Verify that a file can only be preserved once across all active sessions. Attempting to preserve it a second time, whether in the same or a different session, should fail with EBUSY. Signed-off-by: Pasha Tatashin --- .../testing/selftests/liveupdate/liveupdate.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testin= g/selftests/liveupdate/liveupdate.c index c2878e3d5ef9..37c808fbe1e9 100644 --- a/tools/testing/selftests/liveupdate/liveupdate.c +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -345,4 +345,45 @@ TEST_F(liveupdate_device, preserve_unsupported_fd) ASSERT_EQ(close(session_fd), 0); } =20 +/* + * Test Case: Prevent Double Preservation + * + * Verifies that a file (memfd) can only be preserved once across all acti= ve + * sessions. Attempting to preserve it a second time, whether in the same = or + * a different session, should fail with EBUSY. + */ +TEST_F(liveupdate_device, prevent_double_preservation) +{ + int session_fd1, session_fd2, mem_fd; + int ret; + + self->fd1 =3D open(LIVEUPDATE_DEV, O_RDWR); + if (self->fd1 < 0 && errno =3D=3D ENOENT) + SKIP(return, "%s does not exist", LIVEUPDATE_DEV); + ASSERT_GE(self->fd1, 0); + + session_fd1 =3D create_session(self->fd1, "double-preserve-session-1"); + ASSERT_GE(session_fd1, 0); + session_fd2 =3D create_session(self->fd1, "double-preserve-session-2"); + ASSERT_GE(session_fd2, 0); + + mem_fd =3D memfd_create("test-memfd", 0); + ASSERT_GE(mem_fd, 0); + + /* First preservation should succeed */ + ASSERT_EQ(preserve_fd(session_fd1, mem_fd, 0x1111), 0); + + /* Second preservation in a different session should fail with EBUSY */ + ret =3D preserve_fd(session_fd2, mem_fd, 0x2222); + EXPECT_EQ(ret, -EBUSY); + + /* Second preservation in the same session (different token) should fail = with EBUSY */ + ret =3D preserve_fd(session_fd1, mem_fd, 0x3333); + EXPECT_EQ(ret, -EBUSY); + + ASSERT_EQ(close(mem_fd), 0); + ASSERT_EQ(close(session_fd1), 0); + ASSERT_EQ(close(session_fd2), 0); +} + TEST_HARNESS_MAIN --=20 2.43.0