From patchwork Fri Feb 9 16:55:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13551606 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 E8D077EF0A for ; Fri, 9 Feb 2024 16:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497730; cv=none; b=afyZJYolQZ3m7Lq6nvyLu4xV7aCXnZ3zvirNZUcKLLMfVhYDs9LJIEelY8HfksNs/xO8HTDRUdgCbYomsTTXtHVHsk1MCj+K95WsB2s6ZLd0a6fT61TMi9x9IBcnFI6/e15E01hgPqbc662b/dwprcqknSKWQI3RUoDQgzMW1L0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497730; c=relaxed/simple; bh=CyiM5LvSbQYJhEJ6nkB4ZfJ1MbF4QShm1vgGJn1B0r8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=raufauYipvKEZ7GD3sT6dUBSZgNbAAaaHwzImM9rVwWwKTwvf7Wk19sdMUz4iHAYz0Ctwiy4HI4tVmta8zw2sPZz1Xl/pJHWzZ8WZgLoSCB0Hd9jVi7PCm7SZvWI0ck98xDL2/LUXRNM+WWbbIjPZzhtrc74IxxdM91QtZA9AJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=V2PtDGLP; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="V2PtDGLP" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5114b1e8819so1681053e87.1 for ; Fri, 09 Feb 2024 08:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707497726; x=1708102526; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XdKwi9YodNJD282KzK7O3DAPwVLkD53DU5p+wodh61Q=; b=V2PtDGLPAVxuNpt4TFOUmBs4mtAOqzaxiDUyjI6ong2mSOzeuL1bg8Vzh7NGLrVE8k PspK1DZO9M4KBvVwshHiLQrwu65bGRa9KMOF91KegSjbSYt0OdBguWaRRUyFjyiDQBfq rBWrqZJ+QnU56D06CQXPC1gfnVFsprIFLpr/85BQZP0kYs1e10UXfy0FjxQdgbDl8p96 xXltT3oEp1QHrk1nitJVv1dDzLhbEecGZKWj/4Meh/qssYtrlYYPlJ3/9QHBFCBaAug8 4mNuxQpUO4mVWdhLsFIXLVpsgf75pn3kc5sHnKe3DG4hr79lPbE4sPK1NQc897UD4+Hv PS6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707497726; x=1708102526; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XdKwi9YodNJD282KzK7O3DAPwVLkD53DU5p+wodh61Q=; b=H/GDr0aWRQ9tdnAs5VZL83GvddzOdaJ9TzEhhiWnaUjCvr/Zi2t5rDn1GY+atU9Sqm UvpH32tSV4LuHodNTv7IO4+43LLhe9rl86fBifq67W8SJKYyNg6cLZmsaQh3zel8d7j7 N9YteJLicuMfiJULK3UhXvKEqd320a2OUGYeMQMKNVamnejLxsgE7JHekwvIj3x7G/Ez w2giJ2JeBWBFB/Cx36CtQDYPf5PV34t3pkpkhMp4iJYGxQWfeXEwm5kLoM+eJOnCttk0 pSLzWsgsB4LlYkADA14cGgD43WvMGH3d5qn+AEPbcdqZdsD4wUPp7UBcrzwlFCp7JvLi TL5A== X-Gm-Message-State: AOJu0YzBhIeo1ZWjJcHAZdolSxTUD7MTneSXsLV3v3HfvrIiK2K76YVG MSWeNER2nInMOyPEg0lFVQKQshIqVQvZWnbWA/SyNxPrjVfYeq1MyYcHK7J00zU= X-Google-Smtp-Source: AGHT+IEnPbKclbZK1r+x8GBe4uGCB2NXVtUPFTXAG/uwmGtNyD1JXsp6AzTWO/TZfkobPqWJhcA95w== X-Received: by 2002:ac2:5323:0:b0:511:7292:c4db with SMTP id f3-20020ac25323000000b005117292c4dbmr1635947lfh.12.1707497725934; Fri, 09 Feb 2024 08:55:25 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWz6kJIDLeOKtNKbjPe1D54aOwOz2/kq7NfHYP52ckeHVjaWP9ImGoElaDvFKHBixpFBBINB23+pbztQiNF1M9iEasTBsy/k7bGhFBAWMTm7WX+KOFh+8MLt0Utau1Z7T9uEwPzh4T5+Z4UP8PiAK02MnMGguVa73/5I4ZCk2RLFXNzUiWLySOK Received: from localhost (dslb-002-202-118-224.002.202.pools.vodafone-ip.de. [2.202.118.224]) by smtp.gmail.com with UTF8SMTPSA id jd10-20020a05600c68ca00b0040fdc645beesm1142919wmb.20.2024.02.09.08.55.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 08:55:25 -0800 (PST) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, linux-lvm@lists.linux.dev, Zdenek Kabelac , Peter Rajnoha Subject: [PATCH 1/6] 11-dm-mpath.rules: use import logic like 13-dm-disk.rules Date: Fri, 9 Feb 2024 17:55:08 +0100 Message-ID: <20240209165513.7661-2-mwilck@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209165513.7661-1-mwilck@suse.com> References: <20240209165513.7661-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have to import the properties if either DM_NOSCAN or DM_DISABLE_OTHER_RULES_FLAG is set, because blkid will be skipped in both cases. Also, if DM_UDEV_PRIMARY_SOURCE_FLAG is not set, it makes no sense to try and import the properties. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipath/11-dm-mpath.rules.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/multipath/11-dm-mpath.rules.in b/multipath/11-dm-mpath.rules.in index b3117f9..e7be12d 100644 --- a/multipath/11-dm-mpath.rules.in +++ b/multipath/11-dm-mpath.rules.in @@ -79,7 +79,14 @@ ENV{MPATH_DEVICE_READY}!="0", ENV{.MPATH_DEVICE_READY_OLD}=="0", \ # not. If symlinks get lost, systemd may auto-unmount file systems. LABEL="scan_import" -ENV{DM_NOSCAN}!="1", GOTO="import_end" + +# If DM_UDEV_PRIMARY_SOURCE_FLAG is not set, the properties below +# have never been properly set. Don't import them. +ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="1", GOTO="import_end" + +# Don't import the properties from db if we will run blkid later. +ENV{DM_NOSCAN}!="1", ENV{DM_DISABLE_OTHER_RULES_FLAG}!="1", GOTO="import_end" + IMPORT{db}="ID_FS_TYPE" IMPORT{db}="ID_FS_USAGE" IMPORT{db}="ID_FS_UUID_ENC" From patchwork Fri Feb 9 16:55:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13551607 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 C073A7BB1F for ; Fri, 9 Feb 2024 16:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497731; cv=none; b=NSJgGtTb91xTOig808RhAaOE7OG7TQdbbXBBbHL4H+8gLw8IZMdOJeiUFNCk2smiE2BKycVmqH74lgiCbS4zxo76D47UpncKcT6zF2KKJ7EjXPNO46ElmlKntTsq1WFZV/uLGh5KCESyrsOJmV2qOhbm0Xt3J/NrCp8XaQDxbtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497731; c=relaxed/simple; bh=fwzURjxFbzGZIw4dknM4g9VoHn4RkQW/v7GQ9teO0zU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AJh5EqCrrckLG8NK9tOxz/yYZze6HjcLDFYFdDZ7GX8QxhSLnvui7kOiJRUZM14OoK1qzxYS6oll1/1k5/T9vbZh0/oRXOpKdAiEAy32VP4WepjcSQFFqr8+Ycd3WuOiKE635J3/uvm/L1TFJw6WnnTK1vWSkr2ZEwLaEBfHGWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Q5ehqAgw; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Q5ehqAgw" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-33b4b121e28so513195f8f.1 for ; Fri, 09 Feb 2024 08:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707497727; x=1708102527; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ahhAHgV8/qnedlLprsRgwv7yIEBhybb7qNVa4QZ49XA=; b=Q5ehqAgw7YgYRn4/hkep438hAkChQ19h0tBQiOAPXv1QGsUh4A/td/vd9gIDulDPFH 20NOgNRSsL6P+TKgJbngdCATtJZ/S7x2HEqowjw9qj3zwg1V7w+5MDhxJRRwyICf1mZ8 zNuzpP32VBjvuUjtfzZy1QfiNdADHdkF/NDUoZbL1nGnqxuGLJHis85Le+bwn7ezny41 EGARDFqhILLJ44sgwu99OoltM7PaRjK9518sXnBP6GgiRsoAOb22u/dWnMFvNpraBu2i by1RNvASOclbvMleMTh6AO4fBepKapuuwe1KvOKeuJZbe43LxvuvM54r5MQyv3rAQMQC O0nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707497727; x=1708102527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ahhAHgV8/qnedlLprsRgwv7yIEBhybb7qNVa4QZ49XA=; b=QNmaKwCe8YjwsXM6bR7kGeVOmNj9cP7v4rUkxaJQpTqq9DtNJt3QwLu3Yxmtkqo8u0 4O1EangoMEBCOx65dyW33Q8bEON3XLq1GTeq8BQSxuIlTwLMdgqcjbAdImU0Tfl8vav0 TctPMDk6W8bETiq0JVCjJu4IDda/m8ib2hVcEFsSoXQNVZTq3bhgS5Zy8sBF9nQunMZQ FviWurgf8vseRx+A0Vh+ALDD8Fb9JcQqT2f0//prDXqB+nF8pozHLl+oBUpwCGhPimWZ QV8ltz7D1YMN0Qk7JpdOcvKpjKBDQyMvI3sO9VoKckP/jhQWWbpvuur1VDDWOuGbfGKr gqCA== X-Gm-Message-State: AOJu0YzdDAghzeKFM6BueNz/cgBHQFxuT+9cYtU3Jhf0EL4ZgktPH91L r73nhUMPAimpB/evBE/Ia5rNmEEsTJ2p7Q8wg/+udcFtY6X8BxgNDiLVihPEwTQ= X-Google-Smtp-Source: AGHT+IF/qxyZuozmX5MCZBtD7G7Ss97VrOm7ebcbna9t+1hUdnd8fFMQ1788TxcrKVup6kArDCuc+w== X-Received: by 2002:a5d:6550:0:b0:33b:4acb:9999 with SMTP id z16-20020a5d6550000000b0033b4acb9999mr1399208wrv.44.1707497726972; Fri, 09 Feb 2024 08:55:26 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVWBlJKmLXs55l9qo9Lm5eOcgnNnD0vMYN6N9D1xrAfUjUupC7t1aIM/7xazJ+dGBFh5V2pNKny5PuMkHMWjecMf1JXmM2zijvND04Gg0rGiEqcTdJH2dPdJgueQ5oE43TwVD6WC1seFZbSH4AypUc6AvpHSBCr3cp/SPvTc+ZVW+XTPmNVBu+m Received: from localhost (dslb-002-202-118-224.002.202.pools.vodafone-ip.de. [2.202.118.224]) by smtp.gmail.com with UTF8SMTPSA id ba1-20020a0560001c0100b0033b45bdb2a1sm2337464wrb.4.2024.02.09.08.55.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 08:55:26 -0800 (PST) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, linux-lvm@lists.linux.dev, Zdenek Kabelac , Peter Rajnoha Subject: [PATCH 2/6] 11-dm-mpath.rules: don't import properties that are already set Date: Fri, 9 Feb 2024 17:55:09 +0100 Message-ID: <20240209165513.7661-3-mwilck@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209165513.7661-1-mwilck@suse.com> References: <20240209165513.7661-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DM_UDEV_DISABLE_OTHER_RULES_FLAG is handled by 10-dm.rules, which imports it from db if necessary. There is no need to do this again here. DM_NOSCAN may be already set from previous rules, e.g. if the device is suspended. Make sure we don't overwrite it. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipath/11-dm-mpath.rules.in | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/multipath/11-dm-mpath.rules.in b/multipath/11-dm-mpath.rules.in index e7be12d..05c4294 100644 --- a/multipath/11-dm-mpath.rules.in +++ b/multipath/11-dm-mpath.rules.in @@ -7,7 +7,13 @@ IMPORT{db}="MPATH_DEVICE_READY" # If this uevent didn't come from dm, don't try to update the # device state -ENV{DM_COOKIE}!="?*", ENV{DM_ACTION}!="PATH_*", IMPORT{db}="DM_UDEV_DISABLE_OTHER_RULES_FLAG", IMPORT{db}="DM_NOSCAN", GOTO="scan_import" +ENV{DM_COOKIE}=="?*", GOTO="check_ready" +ENV{DM_ACTION}=="PATH_*", GOTO="check_ready" + +ENV{DM_NOSCAN}!="?*", IMPORT{db}="DM_NOSCAN" +GOTO="scan_import" + +LABEL="check_ready" ENV{.MPATH_DEVICE_READY_OLD}="$env{MPATH_DEVICE_READY}" From patchwork Fri Feb 9 16:55:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13551608 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 D298280BFC for ; Fri, 9 Feb 2024 16:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497733; cv=none; b=UtaQKJXcIEM8HCwzFWRY0w78RoRU0X6raIFxAsaSDMjDKNz+V0HOhW3YEbVLS0ZnIqSM0HsuAa5a+5diAZVFvPLvgcTB5pE2/qmVdj+8UUq9LV2fZs5Yx277YR52lz4FVfzRXIdtf5nldW0J8xQ64ZXlww9Yjak/iKhK1FHYMxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497733; c=relaxed/simple; bh=CY+9HPw0UhyXcKqB+f+6KZzsj9LHHgGkJFqDwVC3WJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U64dv+TfbA4erugZGwxfdFRo7RbI+245e1w/E5EzYCP1dEh4LugBifmzXSmQrXMuydWkPIfKr01voBxxJTAFIohVna1NzaCDR6iFZMqxLGjjXKtLvK8xwBmULkFVXbUdpl+66wMi1mZJpfh9RDGIwhYEWYBewc6VoWLjaUspjqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=EKo/fTdQ; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="EKo/fTdQ" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-410489e1a63so9800535e9.3 for ; Fri, 09 Feb 2024 08:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707497728; x=1708102528; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nZUP3Bt+QfIy4ehAUwbxboZetYw8fr65tINadv9Lme0=; b=EKo/fTdQXQTk7qFJN4HrvhiySkWYytrEmk07t69FhyEe90zjWX4V4YXnYxQg5ORoXL LrTXidbGoaDcf4+hEGsmMnpA/iqhNRrfE141zevA7vwkUNjqzN2tQ8KLb44f0Dnz/fUi uBM1NPRIw+gsR+g7QJVio4oIqpkG99FP5Pd+GMTk+45iPTI1SX4QOsD6zOU7eNoAZHRK ak4+GnKkUi+mNnlc5R/Yq02fr7V7EPy1Va+1ExeUze24ay1+KDIRDk3I20n+n47hJR65 wNdFIv+EgTcG35D8Y3ItnZsv2QpDBb533xQYh0z/TxTUDfTNyRs2RuVUXkJGQ3fiYbMW OL1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707497728; x=1708102528; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nZUP3Bt+QfIy4ehAUwbxboZetYw8fr65tINadv9Lme0=; b=n+P2RGuOc/JmuG2WB4RKZHHu27HY9zypHaJKTmqjjijUZ/4ZxAebBCC2M2UBYkfQCi I929R3p6KF5GXVMX9NsubKEp+sbYpor144YtMyItU82ll8yQH9sKMG16GsyeA2LYPRVn MHC1tXr5+/eIbNZ4EAVeblq4Gtoy8cIzpDWAMowW/Di+Dh7th94mz6crRz5GmCrWDO89 PFbsfxN8cV9Niyl4notw0EneCbbS9SW2qPaqyKk34FJZdj3tvA2FTdjAMY4U7juosO3J e3Z2G3JQd6Tm121AdUlUfiLaBHpxm4TX4Qx/Uh7yaELioaqM/+CSKDAgDtrfdwHozMgU YNEg== X-Gm-Message-State: AOJu0YyLYL9s75akdIJ2Hbr0aRKRRVXoJgqg0XWrsyCXAsw7B7/sx6EP vLXY8DgL1DpAbzoxRfHqqRJI1bFBBeCtJXCiZIHKdxc2n2b3/SSm8R4ThtzM+UQ= X-Google-Smtp-Source: AGHT+IF7z0bVzjket9p0pKC+QRj39zfS7OPCoys65M3StKtkMDl67BebHvawrZPf7oQNjs1gtfXH0Q== X-Received: by 2002:a05:600c:3550:b0:40f:d43f:3df with SMTP id i16-20020a05600c355000b0040fd43f03dfmr1483577wmq.21.1707497727987; Fri, 09 Feb 2024 08:55:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXsKK6gTZRYi/up/dlof5WVgJt9RgJllwU4Pbn38Vaz+CWxqUMJsDIbjwNLBGcsYsNNLucewDEF2SS1syckzt0OUo23YBpAX/oPqYE2aPxqic20Y3g7iGgddtnLU5hb268H42AnLLqZxA9zTukUc5vxefzkr/h/SattD3zcJnyuWjsFKvSh7Y48 Received: from localhost (dslb-002-202-118-224.002.202.pools.vodafone-ip.de. [2.202.118.224]) by smtp.gmail.com with UTF8SMTPSA id t3-20020a5d6903000000b0033b2799815csm2229666wru.86.2024.02.09.08.55.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 08:55:27 -0800 (PST) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, linux-lvm@lists.linux.dev, Zdenek Kabelac , Peter Rajnoha Subject: [PATCH 3/6] 11-dm-mpath.rules: handle reloads during coldplug events Date: Fri, 9 Feb 2024 17:55:10 +0100 Message-ID: <20240209165513.7661-4-mwilck@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209165513.7661-1-mwilck@suse.com> References: <20240209165513.7661-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If a map reload happens while udev is processing rules for a coldplug event, DM_SUSPENDED may be set if the respective test in 10-dm.rules happens while the device is suspened. This will cause the rules for all higher block device layers to be skipped. Record this situation in an udev property. The reload operation will trigger another "change" uevent later, which would normally be treated as a reload, and be ignored without rescanning the device. If a previous "coldplug while suspended" situation is detected, perform a full device rescan instead. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipath/11-dm-mpath.rules.in | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/multipath/11-dm-mpath.rules.in b/multipath/11-dm-mpath.rules.in index 05c4294..3b2c3e1 100644 --- a/multipath/11-dm-mpath.rules.in +++ b/multipath/11-dm-mpath.rules.in @@ -11,8 +11,13 @@ ENV{DM_COOKIE}=="?*", GOTO="check_ready" ENV{DM_ACTION}=="PATH_*", GOTO="check_ready" ENV{DM_NOSCAN}!="?*", IMPORT{db}="DM_NOSCAN" -GOTO="scan_import" +# Coldplug event while device is suspended (e.g. during a reload) +ACTION=="add", ENV{DM_ACTIVATION}=="1", ENV{DM_SUSPENDED}=="1", \ + PROGRAM="/bin/logger -t 11-dm-mpath.rules -p daemon.warning \"Coldplug event for suspended device\"", \ + ENV{DM_COLDPLUG_SUSPENDED}="1" + +GOTO="scan_import" LABEL="check_ready" ENV{.MPATH_DEVICE_READY_OLD}="$env{MPATH_DEVICE_READY}" @@ -49,6 +54,16 @@ ENV{DM_ACTION}=="PATH_FAILED", GOTO="mpath_action" ENV{MPATH_DEVICE_READY}="1" LABEL="mpath_action" + +# A previous coldplug event occurred while the device was suspended. +# Activation might have been partially skipped. Activate the device now, +# i.e. disable the MPATH_UNCHANGED logic and set DM_ACTIVATION=1. +IMPORT{db}="DM_COLDPLUG_SUSPENDED" +ENV{DM_COLDPLUG_SUSPENDED}=="1", ENV{DM_SUSPENDED}!="1", \ + ENV{DM_ACTIVATION}="1", ENV{MPATH_UNCHANGED}="0", \ + PROGRAM="/bin/logger -t 11-dm-mpath.rules -p daemon.notice \"Forcing activation of previously suspended device\"", \ + GOTO="force_activation" + # DM_SUBSYSTEM_UDEV_FLAG0 is the "RELOAD" flag for multipath subsystem. # Drop the DM_ACTIVATION flag here as mpath reloads tables if any of its # paths are lost/recovered. For any stack above the mpath device, this is not @@ -63,6 +78,8 @@ ENV{DM_SUBSYSTEM_UDEV_FLAG0}=="1", \ ENV{DM_ACTION}=="PATH_FAILED|PATH_REINSTATED", \ ENV{DM_ACTIVATION}="0", ENV{MPATH_UNCHANGED}="1" +LABEL="force_activation" + # Do not initiate scanning if no path is available, # otherwise there would be a hang or IO error on access. # We'd like to avoid this, especially within udev processing. @@ -105,6 +122,9 @@ IMPORT{db}="ID_PART_GPT_AUTO_ROOT" LABEL="import_end" +# Reset previous DM_COLDPLUG_SUSPENDED if activation happens now +ENV{DM_SUSPENDED}!="1", ENV{DM_ACTIVATION}=="1", ENV{DM_COLDPLUG_SUSPENDED}="" + # Multipath maps should take precedence over their members. ENV{DM_UDEV_LOW_PRIORITY_FLAG}!="1", OPTIONS+="link_priority=50" From patchwork Fri Feb 9 16:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13551609 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 E2F577EF0E for ; Fri, 9 Feb 2024 16:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497733; cv=none; b=JyaPs4OaK1Jwe1Wc/U3+t1ijumFmVwK/JfkoISJSzFEHsh1UN/U0Gd7aZqNagns7K+3ZWuc+FOtA5EirN0HAPshviBq5hy9kec3TGqqZX8Dh0gcjYnVfSanY02EFjX3Pr8y3b31Ue/HBmRr/Q0S6V7mtiKoMNl4n+TRv4RPzNtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497733; c=relaxed/simple; bh=SXYvj1b+MOseL8+lEgF4AvLi170/eT0OY580V1XQT8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kHBgrxWidvsE8NO19qVGEETuAMyS0Vgm1vm1zlwSCv3VjZWKibiW3ZTyvYM0VxrMR5q84I/Gg/C+zQlro3vdAsiub7em47R9GMeuslwTRfq0Czh1uLAM0g/nYcODF8RC474g90sXvpZH/r8SmLvbORKgdGpCS8PvFNUY/COQfnI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=WkLqCRsf; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="WkLqCRsf" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4103be6e938so10258215e9.0 for ; Fri, 09 Feb 2024 08:55:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707497729; x=1708102529; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dqlJLITVZHNFGN83tLwKw1NAwLJPKkkVsxSqbOEAewM=; b=WkLqCRsf5ZvHH7b47mXSwty0FOWZe4VfhYLwhCPhsWQ379Q4/zemE3dgegXFYSMVrK VFQ3rCZzdgAPXMBE62FlXO/i+qLyaVweZ7wiBnRraSffRKj7a6tfyRn6qKttQdm6RxJC yqK2T7FbKF5ZyVdNcyMUUxKITYeZk6qS0CcHkpW+Rmsz3idxSfncYFS1tZCiEWuNW22q zd2RDCsQraXazDQgtVmnXSz7l3fTMarwU/tQxvcIw4Lig3gIXuPS197Da447mAjHmHqH 12bsro/3w5eaOP2FBBor4hmtaSe1IvfEi88u7/er+C8fXkclu3Yb9IQ9suuxEmuDk6Pa BxYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707497729; x=1708102529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dqlJLITVZHNFGN83tLwKw1NAwLJPKkkVsxSqbOEAewM=; b=sz+klmSnxQPETgS8JR2kj38zWg6Z9SIFfVtQ9CdrXLWTGtZgO1pHHF2vKTW7bdm+dL /VatfvtBCHRFPNYCatUSxEkoYLmh4GuJE2tjYkXxQjTm7XVk9V3e77UryOjcq/6OTaTN Gz1BaYWfL9Z89m2Y+/3OX6VZiT0Q6ZDyXwRvBiJ4zj9TWbDUjxdQ1OcXVcJ5N9RJNLTU YnshTUHy7NGtUkYxxp5LC31tWD34FZ+ykwk18P2a7Ycx8aWe92vtPjaeKTfyEr5zbfwR 1Ldn2lSPuJxb3nXnZBIiIbP2Ux4TEtEFa44aPhcY6x5nM0a3sf5khkpnUol1hI/0wzU4 KoQw== X-Gm-Message-State: AOJu0YxgxFICKat6ofYGL3abuMl8tei2O4fqxLwcPtKG6gRvCjImnxMn +QxE1ReYUMkaPdXmtcrK83fiNOa2xQ44iirw8XmedlhzRUN57vXOdr/3qISSFVc= X-Google-Smtp-Source: AGHT+IGbsgyavA69Vtr/UO+n4G1CmYXSNNEdSG+d3/+/0kv9DkPR2KPaKmeQfLVpoR5fmlDMGCQY9g== X-Received: by 2002:a05:600c:1c92:b0:40f:d432:c4a0 with SMTP id k18-20020a05600c1c9200b0040fd432c4a0mr1855357wms.27.1707497728971; Fri, 09 Feb 2024 08:55:28 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUdGHfH2JhzVyZOBs1pCt4S2Z12l5nP38cyyHwpB3yvrAl0NuRjGnkuGALVzD2rSRD7wwgJB66i+xyl+ibKKNA4U9yEwXZsfogDjYpXnjhd8dItfsFFrnoWjJ8tYeAnbusw0SMBE8ueR7BiEKnQqm2u7zO9sZZWaMgf42cIcNLf5PcY/09LP6Lo Received: from localhost (dslb-002-202-118-224.002.202.pools.vodafone-ip.de. [2.202.118.224]) by smtp.gmail.com with UTF8SMTPSA id r4-20020a05600c298400b0040fdc7f4fcdsm1166401wmd.4.2024.02.09.08.55.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 08:55:28 -0800 (PST) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, linux-lvm@lists.linux.dev, Zdenek Kabelac , Peter Rajnoha Subject: [PATCH 4/6] 11-dm-mpath.rules: don't save DM_UDEV_DISABLE_OTHER_RULES_FLAG_OLD Date: Fri, 9 Feb 2024 17:55:11 +0100 Message-ID: <20240209165513.7661-5-mwilck@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209165513.7661-1-mwilck@suse.com> References: <20240209165513.7661-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The current rules overwrite DM_UDEV_DISABLE_OTHER_RULES_FLAG and save its value in DM_UDEV_DISABLE_OTHER_RULES_FLAG_OLD if MPATH_DEVICE_READY changes from 1 to 0, and restore DM_UDEV_DISABLE_OTHER_RULES_FLAG from DM_UDEV_DISABLE_OTHER_RULES_FLAG_OLD when MPATH_DEVICE_READY changes back from 0 to 1. This is wrong for multiple reasons. For "spurious" events, 10-dm.rules will read DM_UDEV_DISABLE_OTHER_RULES_FLAG from the udev db and obtain the value saved by 11-dm-mpath.rules rather than it's own saved value, which confuses the logic in 10-dm.rules. 10-dm.rules sets the flag if either DISK_RO==1 or DM_SUSPENDED==1, and never clears it (it can only be cleared by a new genuine libdm event that doesn't have DM_UDEV_DISABLE_OTHER_RULES_FLAG set, while the device is not suspended). lvm commands may set the flag, too, but AFAICS this is only done for certain types of logical volumes, not for multipath maps. If a previously suspended device is resumed, DM_UDEV_DISABLE_OTHER_RULES_FLAG would be cleared, and it would be wrong for 11-dm-mpath.rules to overwrite it with a previuosly saved value. Likewise, if a uevent arrives for a suspended map, and MPATH_DEVICE_READY happens to switch from 0 to 1, it would be wrong to clear DM_UDEV_DISABLE_OTHER_RULES_FLAG by setting it to a previously saved value. We need to set DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 to prevent follow-up rules from attempting I/O on the device. But don't try to save and restore DM_UDEV_DISABLE_OTHER_RULES_FLAG between uevents. Rather, reset DM_UDEV_DISABLE_OTHER_RULES_FLAG to the value we got from 10-dm.rules in a late rule. I chose "z0" for this rule's prefix to make sure it needs to run very late (after 99-systemd.rules, for example) while still allowing some reasonable space after it. Signed-off-by: Martin Wilck --- multipath/11-dm-mpath.rules.in | 6 +----- multipath/Makefile | 2 ++ multipath/z0-dm-mpath-late.rules | 4 ++++ 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 multipath/z0-dm-mpath-late.rules diff --git a/multipath/11-dm-mpath.rules.in b/multipath/11-dm-mpath.rules.in index 3b2c3e1..b6629a8 100644 --- a/multipath/11-dm-mpath.rules.in +++ b/multipath/11-dm-mpath.rules.in @@ -2,7 +2,6 @@ ACTION!="add|change", GOTO="mpath_end" ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="mpath_end" ENV{DM_UUID}!="mpath-?*", GOTO="mpath_end" -IMPORT{db}="DM_DISABLE_OTHER_RULES_FLAG_OLD" IMPORT{db}="MPATH_DEVICE_READY" # If this uevent didn't come from dm, don't try to update the @@ -89,12 +88,9 @@ ENV{MPATH_DEVICE_READY}=="0", ENV{DM_NOSCAN}="1" # Remember the original value of DM_DISABLE_OTHER_RULES_FLAG # and restore it back once we have at least one path available. ENV{MPATH_DEVICE_READY}=="0", ENV{.MPATH_DEVICE_READY_OLD}=="1", \ - ENV{DM_DISABLE_OTHER_RULES_FLAG_OLD}=="", \ - ENV{DM_DISABLE_OTHER_RULES_FLAG_OLD}="$env{DM_UDEV_DISABLE_OTHER_RULES_FLAG}" + ENV{.MPATH_SAVE_DISABLE_OTHER_RULES_FLAG}="$env{DM_UDEV_DISABLE_OTHER_RULES_FLAG}" ENV{MPATH_DEVICE_READY}=="0", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1" ENV{MPATH_DEVICE_READY}!="0", ENV{.MPATH_DEVICE_READY_OLD}=="0", \ - ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="$env{DM_DISABLE_OTHER_RULES_FLAG_OLD}", \ - ENV{DM_DISABLE_OTHER_RULES_FLAG_OLD}="", \ ENV{DM_ACTIVATION}="1", ENV{MPATH_UNCHANGED}="0" # The code to check multipath state ends here. We need to set diff --git a/multipath/Makefile b/multipath/Makefile index f8c1f5e..2f2569c 100644 --- a/multipath/Makefile +++ b/multipath/Makefile @@ -26,6 +26,7 @@ install: $(Q)$(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir)/ $(Q)$(INSTALL_PROGRAM) -d $(DESTDIR)$(udevrulesdir) $(Q)$(INSTALL_PROGRAM) -m 644 11-dm-mpath.rules $(DESTDIR)$(udevrulesdir) + $(Q)$(INSTALL_PROGRAM) -m 644 z0-dm-mpath-late.rules $(DESTDIR)$(udevrulesdir) $(Q)$(INSTALL_PROGRAM) -m 644 multipath.rules $(DESTDIR)$(udevrulesdir)/56-multipath.rules $(Q)$(INSTALL_PROGRAM) -d $(DESTDIR)$(tmpfilesdir) $(Q)$(INSTALL_PROGRAM) -m 644 tmpfiles.conf $(DESTDIR)$(tmpfilesdir)/multipath.conf @@ -46,6 +47,7 @@ endif uninstall: $(Q)$(RM) $(DESTDIR)$(bindir)/$(EXEC) $(Q)$(RM) $(DESTDIR)$(udevrulesdir)/11-dm-mpath.rules + $(Q)$(RM) $(DESTDIR)$(udevrulesdir)/z0-dm-mpath-late.rules $(Q)$(RM) $(DESTDIR)$(modulesloaddir)/multipath.conf $(Q)$(RM) $(DESTDIR)$(modulesloaddir)/scsi_dh.conf $(Q)$(RM) $(DESTDIR)$(libudevdir)/rules.d/56-multipath.rules diff --git a/multipath/z0-dm-mpath-late.rules b/multipath/z0-dm-mpath-late.rules new file mode 100644 index 0000000..58411ca --- /dev/null +++ b/multipath/z0-dm-mpath-late.rules @@ -0,0 +1,4 @@ +# If DM_UDEV_DISABLE_OTHER_RULES_FLAG was modified in 11-dm-mpath.rules, +# restore it here, lest a temporary value be saved in the udev db +ACTION=="add|change", ENV{DM_UUID}=="mpath-?*", ENV{.MPATH_SAVE_DISABLE_OTHER_RULES_FLAG}="*?", \ + ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="$env{.MPATH_SAVE_DISABLE_OTHER_RULES_FLAG}" From patchwork Fri Feb 9 16:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13551610 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 B367580C1E for ; Fri, 9 Feb 2024 16:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497734; cv=none; b=ZZlfqftOJBvHyxWRYQqQ2JZsexr35tUHRY3eD75Ph+eXWm4rRkdDH3rc68AZPOPIvkx4a0onkvIKSPGibjcztsk53FzLpoXlsS+hh7ofsgxxjlT2k2fIozq5oN3ffXLyyTPHkqzYbcov7QZ4ySBs9V9VNb45rVghV3zkZpfi8lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497734; c=relaxed/simple; bh=kH9lcZgazreTj8Ny2flKgo9+XCPx+sRPzn23GF88NbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tl0zYGgGJoS11iS+y74jM4y1brZ+jwOMW3Q/Mr5jFAstZuoVIFi3S2X2vy4LyPux01VtM3nEojR8+M0TwX5aldy/x6eda9V4NdFdyyPqxQxCo/tAbH4S0uHEGtK6gHSu0knyKR5aIPb5PpXZQaAMw/v/Zb+lDRB7lnFEuMeuIQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=U6fP4B/Q; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="U6fP4B/Q" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4107f854a11so3349335e9.3 for ; Fri, 09 Feb 2024 08:55:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707497730; x=1708102530; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J8Oku1j+uKnNtNBV9SeKgc4Lwc0+MXN/8VQvzoxpbKg=; b=U6fP4B/QKfAQE4zm9rW6eVbfhc2zJJbZ3Q61vtHaET0WDh/+Xje4kGFkizEhzV3Pt8 ansmbmccFa7g28P+czFc+UzLkHNgZy15h5DYQ14jTTS/C/B9rTTvkk1unQ9k+TS/UM6N TmuUlFe/Zl6XA292HaiivuzgN3BM4AZgFBcBF2yOiqAy1NE/nudwhkx4wLCVUMfCgff7 +xbY6VXo23S5xukYFqQkvNzHIAnFROfW+x/flR+JtbW8QNXhYkfELH6hISUf1H3g60Qy zJZSrp6JVlgKp2bBVHsSc0HgjjiwILiApYhhvC/d39+aFazje/Lnu8kUaxhgvgDylNj4 l5cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707497730; x=1708102530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J8Oku1j+uKnNtNBV9SeKgc4Lwc0+MXN/8VQvzoxpbKg=; b=oyCDjJCMgY4/p73QDJkjBIqgx77WpNIJftflN1TR+okFmjNQqhnDDV9mZoZrIMKjSp hfnmTQhqmtSlzWWOrn/UMtE9u3v1phg/vrcJc0NCQPVoCE2bIcbso8f6lIU6LYP2SEwB 3C5K3ow5rTbnm5DcGhiwkASv1ZKLZRIdpYtpNgRLP1tioXY1lNeG5VnZkuyEISDAqVG+ 66YVDTdDHAR6mruCRwXPCTNT1fd4pO/ezjJC4kNLBZzw94NP58LCQLovZVKOlMWw3C3n Fv0oKN24NpGh1xV7SnoEUKaleoWsCjvnOo5aQM+yl3uoBtusT/OFdeaLuWFoqrFf/30w eqcw== X-Gm-Message-State: AOJu0YxjOq2sgPU/MWT2BbUrp5NpWifF/R6kGjJw/hd/HTOuHW4hMGHV F6RMTnSICE/s2D0P3Kouu31Flnn3MfFrekN5N+/gCZUNlxH4YekQWGtEOPHCops= X-Google-Smtp-Source: AGHT+IHp+yQc0h286pv9dp7U3DMCAeFVTrvuiIGJNuDirbK2GsKUlFVddITf8O7xuxjbBtujyS+4yg== X-Received: by 2002:a05:600c:3d95:b0:40e:d30b:6129 with SMTP id bi21-20020a05600c3d9500b0040ed30b6129mr1648094wmb.13.1707497729942; Fri, 09 Feb 2024 08:55:29 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX23k4s0b7nv5CjN15PGm8rQ3X85eTUsG8r02r1NTlVZmP8c6odtdQm94sXNfgyY6USdJctZzVq/jRTe60HFLJN30DqUttrMAmEWDmNT9ahqxV1o2VawSOzSURy0BhC+y+YjVuLVsWjhjYc26brYGAFSjx2BDNSBrILGNmQD4Gn6GVC0rqiicVX Received: from localhost (dslb-002-202-118-224.002.202.pools.vodafone-ip.de. [2.202.118.224]) by smtp.gmail.com with UTF8SMTPSA id t18-20020a05600c199200b0040fc26183e8sm1217227wmq.8.2024.02.09.08.55.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 08:55:29 -0800 (PST) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, linux-lvm@lists.linux.dev, Zdenek Kabelac , Peter Rajnoha Subject: [PATCH 5/6] 11-dm-mpath.rules: clear DM_DISABLE_OTHER_RULES_FLAG for coldplug events Date: Fri, 9 Feb 2024 17:55:12 +0100 Message-ID: <20240209165513.7661-6-mwilck@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209165513.7661-1-mwilck@suse.com> References: <20240209165513.7661-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For all "spurious" events, which includes coldplug events, DM_DISABLE_OTHER_RULES_FLAG will be read from the udev DB in 10-dm.rules. Thus if a previous event saw the device in suspended state, the flag will be set even if the device has meanwhile resumed. Reset the flag if none of the conditions hold that would cause it to be set in a genuine uevent in 10-dm.rules. It would be cleaner to do this in 10-dm.rules directly, but it cannot be done easily, because the flag can also have an origin inside lvm itself; lvm sets it for various kinds of logical volumes. For generic (non-LVM) dm devices, the flag is only set in 10-dm.rules though, so doing this is safe for multipath. Signed-off-by: Martin Wilck --- multipath/11-dm-mpath.rules.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/multipath/11-dm-mpath.rules.in b/multipath/11-dm-mpath.rules.in index b6629a8..21f0c15 100644 --- a/multipath/11-dm-mpath.rules.in +++ b/multipath/11-dm-mpath.rules.in @@ -16,6 +16,13 @@ ACTION=="add", ENV{DM_ACTIVATION}=="1", ENV{DM_SUSPENDED}=="1", \ PROGRAM="/bin/logger -t 11-dm-mpath.rules -p daemon.warning \"Coldplug event for suspended device\"", \ ENV{DM_COLDPLUG_SUSPENDED}="1" +# Coldplug event. DM_UDEV_DISABLE_OTHER_RULES_FLAG has been restored +# from DB in 10-dm.rules. If the device is not suspended, clear the flag. +# This is safe for multipath where DM_UDEV_DISABLE_OTHER_RULES_FLAG is basically +# equivalent to DM_SUSPENDED==! || DISK_RO==1 +ACTION=="add", ENV{DM_ACTIVATION}=="1", ENV{DM_SUSPENDED}!="1", ENV{DISK_RO}!="1", \ + ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="" + GOTO="scan_import" LABEL="check_ready" From patchwork Fri Feb 9 16:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13551611 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 0625A7C0A9 for ; Fri, 9 Feb 2024 16:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497735; cv=none; b=EDj4kCwTGINbLubPeeBQcqcIgl/uB0uHqXDQ62jU/2Qpq82dkpC3bwF715YfEUxv7kROfraqHmaWCf7/eKBqTQw4mWl3hr90w/qqPZI28LexW1CZtuGxB8IfWgBsUllvpkT00ri9af0/6ftPHb0fc5nuU9KNj7uy0eXw/jzP0O0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497735; c=relaxed/simple; bh=XmfUws+oeyOISEqJNNOoqfuX9Z3znjTIsViLY8A4CV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hcQJ/TdG3sckRbxpd20S8uaXjkFTcvil+beWdoqIBsKMC8e9XJi8PWizwbKcHyO8e/9e/phorxJDc6aKFGPVoF+gWkivHZ3n0iZYLCI5PYQK7viUadSDcKXFejUbSvMLyS99o3dlG1B7VuJEpw+8TibKKN/l05XeN7I8Xjp0iSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=gEhG3TwI; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="gEhG3TwI" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-41060e5b664so7944325e9.1 for ; Fri, 09 Feb 2024 08:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707497731; x=1708102531; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sEjWJXUyvIA+QGAomrtyrXXlSTIk0reYqWcesBPAmOE=; b=gEhG3TwIAZrCRpiAmn6JBWCvfyXU4N1+utzf3IGsp2JAWVy9FI7UQ2QOoSxrsRscTJ Hj1w3IwS1WQAhbDorI/Jk03IB53acJVOHeXvq+eiQi/4lxTYxjIWub5oZzGkOw1ob1DK eCbxp7uXRx7STQB93Ezl722GYrmDX3RQXW78aN/QManHK17K+4L+k8bCe4qzWcUu1Bz0 TWjsEicfeagSSvyVtV4ZlAcsdO4pKaIXeR+o8p0OrTFmYrPVy6VlJ/rEN3MIDg7bN0lH 9p1pTx156pKMmlGJrel/iNTACZTdWkGB8n4sZOzeTXh+ytzLmmeLMZpBqO4MT2gZBLk7 2YVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707497731; x=1708102531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sEjWJXUyvIA+QGAomrtyrXXlSTIk0reYqWcesBPAmOE=; b=OqiN1lRQg2zQImpY5nE1fdjrkYdDJxET7/YDEial6imufVEfUbxa8AiV49HiB+8uIW 3Jt+LykQJqb78ZlS0RTFLJLCzcuYvkbVihZj8fYPGjgnUL6AvLVtzZwsJeLDwbRLBli1 SLPu5/Bze9BM61kw/QEcwuZ3055OsOeMSVkVivAjf7tw+w/uEbF4WvsOBqA0j0xbivQF zbWjXd7jo4MCI7syxcIfW0EN/9I0LB5jFngYJqbj78Mz7VmbyDN4aHSQNbLmql17uKYo nlz/phmVnmQnLI2e0JWvNAZEYb8FfEQ6VhG82VH/HTfOSQw6QAF7ZlWXpGPF9NL1ZjWP 2Gyg== X-Gm-Message-State: AOJu0YyeQoJdPlXH5VpuMl/ItxYyKKd63Ly38m+uYhxwu+I1uUtoa9LO yq6Gtko1GcyYD8ZXOJl14kjEq/IGS2JMVfG5AHTxC3my3Fm9HUYQvMLt12qjNpE= X-Google-Smtp-Source: AGHT+IGM57mhy1jDp1rz8QEh7seht6VA/HdX+Xk9vmSmrPJIc9ByX0a/iDnm/p02It6pht927g6ZPw== X-Received: by 2002:a05:600c:600b:b0:40e:ac46:7568 with SMTP id az11-20020a05600c600b00b0040eac467568mr1666877wmb.13.1707497731237; Fri, 09 Feb 2024 08:55:31 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXgPD1wHA+Nps0WVrQoN9Y4DP7MeZS4GpvJXz2WwbJfu6CpE8faavJcBILXrL5fn6j2l377EWvXXfRyA2z3PvfQlbmHkvDpSP2KU4LxwW8PObhf8zRZBnbNAq+I0vA9UCjPD+jxsOizASqA4qojN4EL3i/GfEoy9o9Nn67CKSwF8LilXLzi+bXv Received: from localhost (dslb-002-202-118-224.002.202.pools.vodafone-ip.de. [2.202.118.224]) by smtp.gmail.com with UTF8SMTPSA id jx6-20020a05600c578600b0040ffd94cd27sm1106991wmb.45.2024.02.09.08.55.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 08:55:31 -0800 (PST) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, linux-lvm@lists.linux.dev, Zdenek Kabelac , Peter Rajnoha Subject: [PATCH 6/6] multipath-tools: Makefile.inc: set _FILE_OFFSET_BITS=64 Date: Fri, 9 Feb 2024 17:55:13 +0100 Message-ID: <20240209165513.7661-7-mwilck@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209165513.7661-1-mwilck@suse.com> References: <20240209165513.7661-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Set _FILE_OFFSET_BITS=64 in order to avoid EOVERFLOW error for getdents() syscalls on some file systems (in particular, ext4) in emultated 32bit environments on 64 bit kernel, e.g. when running in qemu. This error occured in arm/v7 CI runs on Ubuntu runners on GitHub, which can be enabled after applying this change. See e.g. https://sourceware.org/bugzilla/show_bug.cgi?id=23960. This change requires fixes for the unit tests: If -D_FILE_OFFSET_BITS=64 is set, glibc headers replace some functions with their 64bit equivalents. open() is replaced by open64(), etc. cmocka wrappers for these functions must have correct name: defining __wrap_open() has no effect for calls to open64(). Unit tests using the wrongly named wrapper functions will fail in non-obvious ways. Use CPP macros to substitute the correct name for affected functions. Also, the Makefile rule that builds the -Wl,wrap= options must parse the C preprocessor output to generate suitable command line parameters for the linker. Signed-off-by: Martin Wilck --- Makefile.inc | 1 + tests/Makefile | 5 ++++- tests/alias.c | 4 ++-- tests/directio.c | 7 +++--- tests/dmevents.c | 8 +++---- tests/sysfs.c | 57 ++++++++++++++++++++++++------------------------ tests/test-lib.c | 9 +++++--- tests/wrap64.h | 48 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 98 insertions(+), 41 deletions(-) create mode 100644 tests/wrap64.h diff --git a/Makefile.inc b/Makefile.inc index a0e36c4..5668e63 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -100,6 +100,7 @@ WARNFLAGS := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implici -Werror=implicit-function-declaration -Werror=format-security \ $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS) CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) \ + -D_FILE_OFFSET_BITS=64 \ -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(plugindir)\" \ -DRUNTIME_DIR=\"$(runtimedir)\" -DCONFIG_DIR=\"$(configdir)\" \ -DDEFAULT_CONFIGFILE=\"$(configfile)\" -DSTATE_DIR=\"$(statedir)\" \ diff --git a/tests/Makefile b/tests/Makefile index 7dac8a8..7dde8bd 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -105,8 +105,11 @@ include $(wildcard $(OBJS:.o=.d)) dep_clean: $(Q)$(RM) $(OBJS:.o=.d) +# Parse the C code for __wrap_xyz() functions and generate linker options from them. +# See comment in wrap64.h %.o.wrap: %.c - @sed -n 's/^.*__wrap_\([a-zA-Z0-9_]*\).*$$/-Wl,--wrap=\1/p' $< | \ + $(Q)$(CC) $(CPPFLAGS) $($*-test_FLAGS) -E $< | \ + sed -n 's/^.*__wrap_\([a-zA-Z0-9_]*\).*$$/-Wl,--wrap=\1/p' | \ sort -u | tr '\n' ' ' >$@ # Pass the original values of CFLAGS etc. to the sub-make, which will include diff --git a/tests/alias.c b/tests/alias.c index c2ae915..95ce994 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -9,7 +9,7 @@ #include "test-log.h" #include #include - +#include "wrap64.h" #include "globals.c" #include "../libmultipath/alias.c" @@ -71,7 +71,7 @@ int __wrap_rename(const char *old, const char *new) return __set_errno(mock_type(int)); } -int __wrap_mkstemp(char *template) +int WRAP_FUNC(mkstemp)(char *template) { return 10; } diff --git a/tests/directio.c b/tests/directio.c index 5201d21..cbedcc9 100644 --- a/tests/directio.c +++ b/tests/directio.c @@ -24,6 +24,7 @@ #include #include #include +#include "wrap64.h" #include "globals.c" #include "../libmultipath/checkers/directio.c" @@ -66,12 +67,12 @@ int __wrap_ioctl(int fd, ioctl_request_t request, void *argp) #endif } -int __real_fcntl(int fd, int cmd, long arg); +int REAL_FCNTL (int fd, int cmd, long arg); -int __wrap_fcntl(int fd, int cmd, long arg) +int WRAP_FCNTL (int fd, int cmd, long arg) { #ifdef DIO_TEST_DEV - return __real_fcntl(fd, cmd, arg); + return REAL_FCNTL(fd, cmd, arg); #else assert_int_equal(fd, test_fd); assert_int_equal(cmd, F_GETFL); diff --git a/tests/dmevents.c b/tests/dmevents.c index f08e649..540bf0d 100644 --- a/tests/dmevents.c +++ b/tests/dmevents.c @@ -29,7 +29,7 @@ #include #include "structs.h" #include "structs_vec.h" - +#include "wrap64.h" #include "globals.c" /* I have to do this to get at the static variables */ #include "../multipathd/dmevents.c" @@ -207,7 +207,7 @@ static int teardown(void **state) return 0; } -int __wrap_open(const char *pathname, int flags) +int WRAP_FUNC(open)(const char *pathname, int flags) { assert_ptr_equal(pathname, "/dev/mapper/control"); assert_int_equal(flags, O_RDWR); @@ -389,7 +389,7 @@ static void test_init_waiter_bad1(void **state) struct test_data *datap = (struct test_data *)(*state); if (datap == NULL) skip(); - will_return(__wrap_open, -1); + wrap_will_return(WRAP_FUNC(open), -1); assert_int_equal(init_dmevent_waiter(&datap->vecs), -1); assert_ptr_equal(waiter, NULL); } @@ -400,7 +400,7 @@ static void test_init_waiter_good0(void **state) struct test_data *datap = (struct test_data *)(*state); if (datap == NULL) skip(); - will_return(__wrap_open, 2); + wrap_will_return(WRAP_FUNC(open), 2); assert_int_equal(init_dmevent_waiter(&datap->vecs), 0); assert_ptr_not_equal(waiter, NULL); } diff --git a/tests/sysfs.c b/tests/sysfs.c index 6e07efd..fc256d8 100644 --- a/tests/sysfs.c +++ b/tests/sysfs.c @@ -18,6 +18,7 @@ #include "test-log.h" #include "sysfs.h" #include "util.h" +#include "wrap64.h" #define TEST_FD 123 @@ -28,7 +29,7 @@ char *__wrap_udev_device_get_syspath(struct udev_device *ud) return val; } -int __wrap_open(const char *pathname, int flags) +int WRAP_FUNC(open)(const char *pathname, int flags) { int ret; @@ -166,10 +167,10 @@ static void test_sagv_open_fail(void **state) will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/bar'"); - expect_string(__wrap_open, pathname, "/foo/bar"); - expect_value(__wrap_open, flags, O_RDONLY); + expect_string(WRAP_FUNC(open), pathname, "/foo/bar"); + expect_value(WRAP_FUNC(open), flags, O_RDONLY); errno = ENOENT; - will_return(__wrap_open, -1); + wrap_will_return(WRAP_FUNC(open), -1); expect_condlog(3, "__sysfs_attr_get_value: attribute '/foo/bar' cannot be opened"); assert_int_equal(sysfs_attr_get_value((void *)state, "bar", buf, sizeof(buf)), -ENOENT); @@ -181,9 +182,9 @@ static void test_sagv_read_fail(void **state) will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/bar'"); - expect_string(__wrap_open, pathname, "/foo/bar"); - expect_value(__wrap_open, flags, O_RDONLY); - will_return(__wrap_open, TEST_FD); + expect_string(WRAP_FUNC(open), pathname, "/foo/bar"); + expect_value(WRAP_FUNC(open), flags, O_RDONLY); + wrap_will_return(WRAP_FUNC(open), TEST_FD); expect_value(__wrap_read, fd, TEST_FD); expect_value(__wrap_read, count, sizeof(buf)); errno = EISDIR; @@ -196,9 +197,9 @@ static void test_sagv_read_fail(void **state) will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/baz'"); - expect_string(__wrap_open, pathname, "/foo/baz"); - expect_value(__wrap_open, flags, O_RDONLY); - will_return(__wrap_open, TEST_FD); + expect_string(WRAP_FUNC(open), pathname, "/foo/baz"); + expect_value(WRAP_FUNC(open), flags, O_RDONLY); + wrap_will_return(WRAP_FUNC(open), TEST_FD); expect_value(__wrap_read, fd, TEST_FD); expect_value(__wrap_read, count, sizeof(buf)); errno = EPERM; @@ -222,9 +223,9 @@ static void _test_sagv_read(void **state, unsigned int bufsz) memset(buf, '.', sizeof(buf)); will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/bar'"); - expect_string(__wrap_open, pathname, "/foo/bar"); - expect_value(__wrap_open, flags, O_RDONLY); - will_return(__wrap_open, TEST_FD); + expect_string(WRAP_FUNC(open), pathname, "/foo/bar"); + expect_value(WRAP_FUNC(open), flags, O_RDONLY); + wrap_will_return(WRAP_FUNC(open), TEST_FD); expect_value(__wrap_read, fd, TEST_FD); expect_value(__wrap_read, count, bufsz); will_return(__wrap_read, sizeof(input) - 1); @@ -249,9 +250,9 @@ static void _test_sagv_read(void **state, unsigned int bufsz) memset(buf, '.', sizeof(buf)); will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/baz'"); - expect_string(__wrap_open, pathname, "/foo/baz"); - expect_value(__wrap_open, flags, O_RDONLY); - will_return(__wrap_open, TEST_FD); + expect_string(WRAP_FUNC(open), pathname, "/foo/baz"); + expect_value(WRAP_FUNC(open), flags, O_RDONLY); + wrap_will_return(WRAP_FUNC(open), TEST_FD); expect_value(__wrap_read, fd, TEST_FD); expect_value(__wrap_read, count, bufsz); will_return(__wrap_read, sizeof(input) - 1); @@ -300,9 +301,9 @@ static void _test_sagv_read_zeroes(void **state, unsigned int bufsz) memset(buf, '.', sizeof(buf)); will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/bar'"); - expect_string(__wrap_open, pathname, "/foo/bar"); - expect_value(__wrap_open, flags, O_RDONLY); - will_return(__wrap_open, TEST_FD); + expect_string(WRAP_FUNC(open), pathname, "/foo/bar"); + expect_value(WRAP_FUNC(open), flags, O_RDONLY); + wrap_will_return(WRAP_FUNC(open), TEST_FD); expect_value(__wrap_read, fd, TEST_FD); expect_value(__wrap_read, count, bufsz); will_return(__wrap_read, sizeof(input) - 1); @@ -385,10 +386,10 @@ static void test_sasv_open_fail(void **state) will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/bar'"); - expect_string(__wrap_open, pathname, "/foo/bar"); - expect_value(__wrap_open, flags, O_WRONLY); + expect_string(WRAP_FUNC(open), pathname, "/foo/bar"); + expect_value(WRAP_FUNC(open), flags, O_WRONLY); errno = EPERM; - will_return(__wrap_open, -1); + wrap_will_return(WRAP_FUNC(open), -1); expect_condlog(3, "sysfs_attr_set_value: attribute '/foo/bar' cannot be opened"); assert_int_equal(sysfs_attr_set_value((void *)state, "bar", buf, sizeof(buf)), -EPERM); @@ -400,9 +401,9 @@ static void test_sasv_write_fail(void **state) will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/bar'"); - expect_string(__wrap_open, pathname, "/foo/bar"); - expect_value(__wrap_open, flags, O_WRONLY); - will_return(__wrap_open, TEST_FD); + expect_string(WRAP_FUNC(open), pathname, "/foo/bar"); + expect_value(WRAP_FUNC(open), flags, O_WRONLY); + wrap_will_return(WRAP_FUNC(open), TEST_FD); expect_value(__wrap_write, fd, TEST_FD); expect_value(__wrap_write, count, sizeof(buf)); errno = EISDIR; @@ -421,9 +422,9 @@ static void _test_sasv_write(void **state, unsigned int n_written) assert_in_range(n_written, 0, sizeof(buf)); will_return(__wrap_udev_device_get_syspath, "/foo"); expect_condlog(4, "open '/foo/bar'"); - expect_string(__wrap_open, pathname, "/foo/bar"); - expect_value(__wrap_open, flags, O_WRONLY); - will_return(__wrap_open, TEST_FD); + expect_string(WRAP_FUNC(open), pathname, "/foo/bar"); + expect_value(WRAP_FUNC(open), flags, O_WRONLY); + wrap_will_return(WRAP_FUNC(open), TEST_FD); expect_value(__wrap_write, fd, TEST_FD); expect_value(__wrap_write, count, sizeof(buf)); will_return(__wrap_write, n_written); diff --git a/tests/test-lib.c b/tests/test-lib.c index f75ea31..665d438 100644 --- a/tests/test-lib.c +++ b/tests/test-lib.c @@ -16,6 +16,7 @@ #include "propsel.h" #include "unaligned.h" #include "test-lib.h" +#include "wrap64.h" const int default_mask = (DI_SYSFS|DI_BLACKLIST|DI_WWID|DI_CHECKER|DI_PRIO|DI_SERIAL); const char default_devnode[] = "sdxTEST"; @@ -38,16 +39,18 @@ const char default_wwid_1[] = "TEST-WWID-1"; * resolved by the assembler before the linking stage. */ -int __real_open(const char *path, int flags, int mode); + +int REAL_FUNC(open)(const char *path, int flags, int mode); static const char _mocked_filename[] = "mocked_path"; -int __wrap_open(const char *path, int flags, int mode) + +int WRAP_FUNC(open)(const char *path, int flags, int mode) { condlog(4, "%s: %s", __func__, path); if (!strcmp(path, _mocked_filename)) return 111; - return __real_open(path, flags, mode); + return REAL_FUNC(open)(path, flags, mode); } int __wrap_libmp_get_version(int which, unsigned int version[3]) diff --git a/tests/wrap64.h b/tests/wrap64.h new file mode 100644 index 0000000..8c91d27 --- /dev/null +++ b/tests/wrap64.h @@ -0,0 +1,48 @@ +#ifndef _WRAP64_H +#define _WRAP64_H 1 +#include "util.h" + +/* + * Make cmocka work with _FILE_OFFSET_BITS == 64 + * + * If -D_FILE_OFFSET_BITS=64 is set, glibc headers replace some functions with + * their 64bit equivalents. "open()" is replaced by "open64()", etc. cmocka + * wrappers for these functions must have correct name __wrap_open() doesn't + * work if the function called is not open() but open64(). Consequently, unit + * tests using such wrappers will fail. + * Use some CPP trickery to insert the correct name. The Makefile rule that + * creates the .wrap file must parse the C preprocessor output to generate the + * correct -Wl,wrap= option. + */ + +/* Without this indirection, WRAP_FUNC(x) would be expanded to __wrap_WRAP_NAME(x) */ +#define CONCAT2_(x, y) x ## y +#define CONCAT2(x, y) CONCAT2_(x, y) + +#if defined(__GLIBC__) && _FILE_OFFSET_BITS == 64 +#define WRAP_NAME(x) x ## 64 +#else +#define WRAP_NAME(x) x +#endif +#define WRAP_FUNC(x) CONCAT2(__wrap_, WRAP_NAME(x)) +#define REAL_FUNC(x) CONCAT2(__real_, WRAP_NAME(x)) + +/* + * fcntl() needs special treatment; fcntl64() has been introduced in 2.28. + * https://savannah.gnu.org/forum/forum.php?forum_id=9205 + */ +#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 28) +#define WRAP_FCNTL_NAME WRAP_NAME(fcntl) +#else +#define WRAP_FCNTL_NAME fcntl +#endif +#define WRAP_FCNTL CONCAT2(__wrap_, WRAP_FCNTL_NAME) +#define REAL_FCNTL CONCAT2(__real_, WRAP_FCNTL_NAME) + +/* + * will_return() is itself a macro that uses CPP "stringizing". We need a + * macro indirection to make sure the *value* of WRAP_FUNC() is stringized + * (see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html). + */ +#define wrap_will_return(x, y) will_return(x, y) +#endif