From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jes Sorensen Subject: Re: [PATCH] Monitor: improve check_one_sharer() for checking duplicated process Date: Mon, 27 Apr 2020 10:27:17 -0400 Message-ID: <4a177b2d-f054-cffc-f970-1ec63e74701a@trained-monkey.org> References: <20200410162446.6292-1-colyli@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20200410162446.6292-1-colyli@suse.de> Content-Language: en-US Sender: linux-raid-owner@vger.kernel.org To: Coly Li , linux-raid@vger.kernel.org Cc: Shinkichi Yamazaki List-Id: linux-raid.ids On 4/10/20 12:24 PM, Coly Li wrote: > When running mdadm monitor with scan mode, only one autorebuild process > is allowed. check_one_sharer() checks duplicated process by following > steps, > 1) Read autorebuild.pid file, > - if file does not exist, no duplicated process, go to 3). > - if file exists, continue to next step. > 2) Read pid number from autorebuild.pid file, then check procfs pid > directory /proc/, > - if the directory does not exist, no duplicated process, go to 3) > - if the directory exists, print error message for duplicated process > and exit this mdadm. > 3) Write current pid into autorebuild.pid file, continue to monitor in > scan mode. > > The problem for the above step 2) is, if after system reboots and > another different process happens to have exact same pid number which > autorebuild.pid file records, check_one_sharer() will treat it as a > duplicated mdadm process and returns error with message "Only one > autorebuild process allowed in scan mode, aborting". > > This patch tries to fix the above same-pid-but-different-process issue > by one more step to check the process command name, > 1) Read autorebuild.pid file > - if file does not exist, no duplicated process, go to 4). > - if file exists, continue to next step. > 2) Read pid number from autorebuild.pid file, then check procfs file > comm with the specific pid directory /proc//comm > - if the file does not exit, it means the directory /proc/ does > not exist, go to 4) > - if the file exits, continue next step > 3) Read process command name from /proc//comm, compare the command > name with "mdadm" process name, > - if not equal, no duplicated process, goto 4) > - if strings are equal, print error message for duplicated process > and exit this mdadm. > 4) Write current pid into autorebuild.pid file, continue to monitor in > scan mode. > > Now check_one_sharer() returns error for duplicated process only when > the recorded pid from autorebuild.pid exists, and the process has exact > same command name as "mdadm". > > Reported-by: Shinkichi Yamazaki > Signed-off-by: Coly Li > --- > Monitor.c | 32 ++++++++++++++++++++------------ > 1 file changed, 20 insertions(+), 12 deletions(-) Applied! Thanks, Jes