From c4415fabcdaf621b0c8fa3ba33d53908de6242a1 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Tue, 16 Aug 2022 15:30:56 -0600 Subject: [PATCH] LU-16056 libcfs: restore umask handling in kernel threads This reverts commit 9013eb2bb5 which incorrectly assumes that Lustre service threads do not modify umask. A quick grep shows that umask is modified in osd-ldiskfs __osd_create(). If some other thread sharing the same fs context is modifying umask in an incompatible way (which includes all Lustre threads after this patch) then it will occasionally break created file access permissions for Lustre. Lustre-change: https://review.whamcloud.com/48233 Lustre-commit: TBD (from e88334d806687ad2512323f1e4c2667348f02a4e) Fixes: 9013eb2bb5 (LU-9859 libcfs: don't call unshare_fs_struct()") Signed-off-by: Andreas Dilger Change-Id: I589b72e4286dc84f4e3f1a0c54fe31aa988e6c18 Reviewed-on: https://review.whamcloud.com/48236 Tested-by: jenkins Reviewed-by: Shuichi Ihara Reviewed-by: Lai Siyao Tested-by: Maloo --- lustre/ldlm/ldlm_lib.c | 2 ++ lustre/ldlm/ldlm_request.c | 2 ++ lustre/obdclass/llog.c | 2 ++ lustre/ptlrpc/import.c | 22 ++++++++++++---------- lustre/ptlrpc/pinger.c | 2 ++ lustre/ptlrpc/ptlrpcd.c | 2 ++ lustre/ptlrpc/service.c | 3 +++ 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index fca4cf1..8c6ccd7 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -40,6 +40,7 @@ #define DEBUG_SUBSYSTEM S_LDLM #include +#include #include #include #include @@ -2717,6 +2718,7 @@ static int target_recovery_thread(void *arg) int rc = 0; ENTRY; + unshare_fs_struct(); OBD_ALLOC_PTR(thread); if (thread == NULL) RETURN(-ENOMEM); diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c index 6ac00de..04f4826 100644 --- a/lustre/ldlm/ldlm_request.c +++ b/lustre/ldlm/ldlm_request.c @@ -57,6 +57,7 @@ #define DEBUG_SUBSYSTEM S_LDLM +#include #include #include #include @@ -2605,6 +2606,7 @@ static int ldlm_lock_replay_thread(void *data) { struct obd_import *imp = data; + unshare_fs_struct(); CDEBUG(D_HA, "lock replay thread %s to %s@%s\n", imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), imp->imp_connection->c_remote_uuid.uuid); diff --git a/lustre/obdclass/llog.c b/lustre/obdclass/llog.c index f8b77b9..7f1f169 100644 --- a/lustre/obdclass/llog.c +++ b/lustre/obdclass/llog.c @@ -43,6 +43,7 @@ #define DEBUG_SUBSYSTEM S_LOG +#include #include #include #include @@ -825,6 +826,7 @@ static int llog_process_thread_daemonize(void *arg) } task_unlock(lpi->lpi_reftask); + unshare_fs_struct(); /* client env has no keys, tags is just 0 */ rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD); if (rc) diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c index 79afbb2..2acb6e6 100644 --- a/lustre/ptlrpc/import.c +++ b/lustre/ptlrpc/import.c @@ -36,6 +36,7 @@ #define DEBUG_SUBSYSTEM S_RPC +#include #include #include #include @@ -1517,19 +1518,20 @@ static int signal_completed_replay(struct obd_import *imp) */ static int ptlrpc_invalidate_import_thread(void *data) { - struct obd_import *imp = data; + struct obd_import *imp = data; - ENTRY; - CDEBUG(D_HA, "thread invalidate import %s to %s@%s\n", - imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), - imp->imp_connection->c_remote_uuid.uuid); + ENTRY; + unshare_fs_struct(); + CDEBUG(D_HA, "thread invalidate import %s to %s@%s\n", + imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), + imp->imp_connection->c_remote_uuid.uuid); - ptlrpc_invalidate_import(imp); + ptlrpc_invalidate_import(imp); - if (obd_dump_on_eviction) { - CERROR("dump the log upon eviction\n"); - libcfs_debug_dumplog(); - } + if (obd_dump_on_eviction) { + CERROR("dump the log upon eviction\n"); + libcfs_debug_dumplog(); + } import_set_state(imp, LUSTRE_IMP_RECOVER); ptlrpc_import_recovery_state_machine(imp); diff --git a/lustre/ptlrpc/pinger.c b/lustre/ptlrpc/pinger.c index f6f536c..9057568 100644 --- a/lustre/ptlrpc/pinger.c +++ b/lustre/ptlrpc/pinger.c @@ -36,6 +36,7 @@ #define DEBUG_SUBSYSTEM S_RPC +#include #include #include #include @@ -468,6 +469,7 @@ static int ping_evictor_main(void *arg) time64_t expire_time; ENTRY; + unshare_fs_struct(); CDEBUG(D_HA, "Starting Ping Evictor\n"); pet_state = PET_READY; while (1) { diff --git a/lustre/ptlrpc/ptlrpcd.c b/lustre/ptlrpc/ptlrpcd.c index 42cb328..79f37cc 100644 --- a/lustre/ptlrpc/ptlrpcd.c +++ b/lustre/ptlrpc/ptlrpcd.c @@ -51,6 +51,7 @@ #define DEBUG_SUBSYSTEM S_RPC +#include #include #include #include @@ -442,6 +443,7 @@ static int ptlrpcd(void *arg) int exit = 0; ENTRY; + unshare_fs_struct(); if (cfs_cpt_bind(cfs_cpt_tab, pc->pc_cpt) != 0) CWARN("Failed to bind %s on CPT %d\n", pc->pc_name, pc->pc_cpt); diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index 3e2dcdd..8a48bcd 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -32,6 +32,7 @@ #define DEBUG_SUBSYSTEM S_RPC +#include #include #include @@ -2739,6 +2740,7 @@ static int ptlrpc_main(void *arg) int counter = 0, rc = 0; ENTRY; + unshare_fs_struct(); thread->t_task = current; thread->t_pid = current->pid; @@ -2945,6 +2947,7 @@ static int ptlrpc_hr_main(void *arg) struct lu_env *env; int rc; + unshare_fs_struct(); OBD_ALLOC_PTR(env); if (env == NULL) RETURN(-ENOMEM); -- 1.8.3.1