From nobody Tue Feb 10 01:59:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5B03EB64DC for ; Sun, 25 Jun 2023 12:17:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232143AbjFYMRt (ORCPT ); Sun, 25 Jun 2023 08:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232112AbjFYMRj (ORCPT ); Sun, 25 Jun 2023 08:17:39 -0400 Received: from out0-195.mail.aliyun.com (out0-195.mail.aliyun.com [140.205.0.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C869AE48; Sun, 25 Jun 2023 05:17:23 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047206;MF=changxian.cqs@antgroup.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---.TdJuHZE_1687695439; Received: from localhost(mailfrom:changxian.cqs@antgroup.com fp:SMTPD_---.TdJuHZE_1687695439) by smtp.aliyun-inc.com; Sun, 25 Jun 2023 20:17:20 +0800 From: "Qingsong Chen" To: linux-kernel@vger.kernel.org Cc: "=?UTF-8?B?55Sw5rSq5Lqu?=" , "Qingsong Chen" , "Miguel Ojeda" , "Alex Gaynor" , "Wedson Almeida Filho" , "Boqun Feng" , "Gary Guo" , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , "Benno Lossin" , Subject: [RFC PATCH 3/8] rust: kernel: add some hook TargetOperations Date: Sun, 25 Jun 2023 20:16:52 +0800 Message-Id: <20230625121657.3631109-4-changxian.cqs@antgroup.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625121657.3631109-1-changxian.cqs@antgroup.com> References: <20230625121657.3631109-1-changxian.cqs@antgroup.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" - Add hooks when suspend or resume a target. - Add operation to check if a target is busy. Signed-off-by: Qingsong Chen --- rust/kernel/device_mapper.rs | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/rust/kernel/device_mapper.rs b/rust/kernel/device_mapper.rs index 153bae3aad79..aeda12245171 100644 --- a/rust/kernel/device_mapper.rs +++ b/rust/kernel/device_mapper.rs @@ -64,6 +64,42 @@ fn rq_end_io( ) -> EndState { unimplemented!() } + + /// Hook presuspend. + #[allow(unused)] + fn presuspend(t: &mut Target) { + unimplemented!() + } + + /// Hook presuspend_undo. + #[allow(unused)] + fn presuspend_undo(t: &mut Target) { + unimplemented!() + } + + /// Hook postsuspend. + #[allow(unused)] + fn postsuspend(t: &mut Target) { + unimplemented!() + } + + /// Hook preresume. + #[allow(unused)] + fn preresume(t: &mut Target) -> Result { + unimplemented!() + } + + /// Hook resume. + #[allow(unused)] + fn resume(t: &mut Target) { + unimplemented!() + } + + /// Check if target is busy. + #[allow(unused)] + fn busy(t: &mut Target) -> bool { + unimplemented!() + } } =20 /// Wrap the kernel struct `target_type`. @@ -130,6 +166,12 @@ pub fn register( ), (HAS_END_IO, end_io, dm_endio_fn), (HAS_RQ_END_IO, rq_end_io, dm_request_endio_fn), + (HAS_PRESUSPEND, presuspend, dm_presuspend_fn), + (HAS_PRESUSPEND_UNDO, presuspend_undo, dm_presuspend_u= ndo_fn), + (HAS_POSTSUSPEND, postsuspend, dm_postsuspend_fn), + (HAS_PRERESUME, preresume, dm_preresume_fn), + (HAS_RESUME, resume, dm_resume_fn), + (HAS_BUSY, busy, dm_busy_fn), ); =20 to_result(bindings::dm_register_target(tt)) @@ -251,6 +293,40 @@ impl TargetType { T::rq_end_io(t, rq, map_ctx, (error as u32).into()) as _ } } + unsafe extern "C" fn dm_presuspend_fn(ti: *mut bi= ndings::dm_target) { + // SAFETY: the kernel should pass valid `dm_target` pointer. + let t =3D unsafe { Target::borrow_mut(ti) }; + T::presuspend(t); + } + unsafe extern "C" fn dm_presuspend_undo_fn(ti: *m= ut bindings::dm_target) { + // SAFETY: the kernel should pass valid `dm_target` pointer. + let t =3D unsafe { Target::borrow_mut(ti) }; + T::presuspend_undo(t); + } + unsafe extern "C" fn dm_postsuspend_fn(ti: *mut b= indings::dm_target) { + // SAFETY: the kernel should pass valid `dm_target` pointer. + let t =3D unsafe { Target::borrow_mut(ti) }; + T::postsuspend(t); + } + unsafe extern "C" fn dm_preresume_fn( + ti: *mut bindings::dm_target, + ) -> core::ffi::c_int { + // SAFETY: the kernel should pass valid `dm_target` pointer. + let t =3D unsafe { Target::borrow_mut(ti) }; + T::preresume(t).map_or_else(|e| e.to_errno(), |_| 0) + } + unsafe extern "C" fn dm_resume_fn(ti: *mut bindin= gs::dm_target) { + // SAFETY: the kernel should pass valid `dm_target` pointer. + let t =3D unsafe { Target::borrow_mut(ti) }; + T::resume(t); + } + unsafe extern "C" fn dm_busy_fn( + ti: *mut bindings::dm_target, + ) -> core::ffi::c_int { + // SAFETY: the kernel should pass valid `dm_target` pointer. + let t =3D unsafe { Target::borrow_mut(ti) }; + T::busy(t) as _ + } } =20 /// Wrap the kernel struct `dm_target`. --=20 2.40.1