From patchwork Mon Mar 27 16:11:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1761783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=g9A06O1B; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pld9z2BCfz1yYf for ; Tue, 28 Mar 2023 03:12:07 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4F05D3CCCF9 for ; Mon, 27 Mar 2023 18:12:05 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 8A3043CA955 for ; Mon, 27 Mar 2023 18:11:52 +0200 (CEST) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id CA953601E8D for ; Mon, 27 Mar 2023 18:11:51 +0200 (CEST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54196bfcd5fso91011277b3.4 for ; Mon, 27 Mar 2023 09:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679933510; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OnUBlM2QF0u4kCUBpJyJfqUrBWT/0YSKm2QOLBU3x/o=; b=g9A06O1BMCzIvvciAQtyVnrp5LV/Pd5MyzVLmqwoPtEk7r4FtiHvzUYqug4HzkCLdo cwNrQVgXRfCSoVvGCU85xEDPS2vAqHVwyKFTLwRrZt+5xHsxfH4PH0utMBMKDukImDNB 600b7DwQOTAbkCAsmWGt8pMNUJ4p7DQB+HAj5e1HajjUoBRFzYBaHb/14q4Ls/Jt6xlM vm0sOctdpnaUXtola7Bqo77zUBr1dRW1JctlE4bhjX7ey5U+2yZoRxIF+Lj/pA0YWAyN NAfM4dMW9R3VtLiPukcIUNqlpW7Tn6cYpQF9YQ07TZ4Mw1lEeJ73T2N2sbmmiMWBXSxH 7Erg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679933510; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OnUBlM2QF0u4kCUBpJyJfqUrBWT/0YSKm2QOLBU3x/o=; b=tLKdJGpMnMZeMyB/bi+xlR7NClBz3qBok4hdPZ5aEitaGo/HeT20PdK70j8juGod10 jMao1PqqtKXZv+wMvwK/fy1ce5SbPfosMFMHp7aOrTwGqZHVINBJb240l40MUHsj9WcU r+CuHKw/o1GETIT7PDsw9SrGHpWcRHPo2TTDCXEBY4Eh5CDpo55xh45cJD69v9NClmEE kflHYc3MkGEQBoJZPZ7+Ut2zit8nMIigfjh2G35x2cBN6NuqnEgMMC8k0qaaPuGP4VY2 HchVJVjuaBgrZKCKdfHXummjLUCFB4GLYUXtfN2wQWJKR3wRGLBOdncMtJ+NMd9SVDH2 KUKg== X-Gm-Message-State: AAQBX9cWIorugqO4s4xiFOp3QYMHjOpdojsS0PmMdKNbPlhlmO4Tq68y FM/t73QHySHR0lwljgE+5VZWj1VP/oTUy5Ivcz9xfXM3LHOLgi3LVbE4jg+KmuqC+BTulbw/n/7 GBP2tp0rxaWGuST3DN4t/LOkyzUi/u/DFNnZVyI7OTM7ZqP7sRTfK8NhH X-Google-Smtp-Source: AKy350Yi5LZIYYOLmLQ7w7G8thxr+JWj1E9mO8PUrcbNdEK7EuoVRF8qVxXWKVGZCYuouY/hp3n9jV0+jBA= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a25:e054:0:b0:b6b:d3f3:45af with SMTP id x81-20020a25e054000000b00b6bd3f345afmr8062817ybg.1.1679933510675; Mon, 27 Mar 2023 09:11:50 -0700 (PDT) Date: Mon, 27 Mar 2023 16:11:42 +0000 In-Reply-To: <20230327161145.1702680-1-edliaw@google.com> Mime-Version: 1.0 References: <20230327161145.1702680-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230327161145.1702680-2-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v4 1/4] set_dev_path: Rename to set_dev_loop_path X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Rename set_dev_path to set_dev_loop_path and the array dev_variants to dev_loop_variants. This will differentiate it from adding a similar function that is checking a more generic dev path. Signed-off-by: Edward Liaw Reviewed-by: Petr Vorel --- lib/tst_device.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/tst_device.c b/lib/tst_device.c index b4a6b8e82..82550dbcd 100644 --- a/lib/tst_device.c +++ b/lib/tst_device.c @@ -54,19 +54,19 @@ static char dev_path[PATH_MAX]; static int device_acquired; static unsigned long prev_dev_sec_write; -static const char *dev_variants[] = { +static const char *dev_loop_variants[] = { "/dev/loop%i", "/dev/loop/%i", "/dev/block/loop%i" }; -static int set_dev_path(int dev, char *path, size_t path_len) +static int set_dev_loop_path(int dev, char *path, size_t path_len) { unsigned int i; struct stat st; - for (i = 0; i < ARRAY_SIZE(dev_variants); i++) { - snprintf(path, path_len, dev_variants[i], dev); + for (i = 0; i < ARRAY_SIZE(dev_loop_variants); i++) { + snprintf(path, path_len, dev_loop_variants[i], dev); if (stat(path, &st) == 0 && S_ISBLK(st.st_mode)) return 1; @@ -89,7 +89,7 @@ int tst_find_free_loopdev(char *path, size_t path_len) close(ctl_fd); if (rc >= 0) { if (path) - set_dev_path(rc, path, path_len); + set_dev_loop_path(rc, path, path_len); tst_resm(TINFO, "Found free device %d '%s'", rc, path ?: ""); return rc; @@ -116,7 +116,7 @@ int tst_find_free_loopdev(char *path, size_t path_len) */ for (i = 0; i < 256; i++) { - if (!set_dev_path(i, buf, sizeof(buf))) + if (!set_dev_loop_path(i, buf, sizeof(buf))) continue; dev_fd = open(buf, O_RDONLY); From patchwork Mon Mar 27 16:11:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1761784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=qUw9KZvI; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PldBG349Wz1yYf for ; Tue, 28 Mar 2023 03:12:22 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0E7C03CCE37 for ; Mon, 27 Mar 2023 18:12:20 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id F0DF03CCCF4 for ; Mon, 27 Mar 2023 18:11:53 +0200 (CEST) Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id A1D3160009E for ; Mon, 27 Mar 2023 18:11:53 +0200 (CEST) Received: by mail-yb1-xb4a.google.com with SMTP id i11-20020a256d0b000000b0086349255277so9181055ybc.8 for ; Mon, 27 Mar 2023 09:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679933512; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FkLtaHCwb4+H4c96s1kPfDfzicrJaxUvZt9EyVW2Phs=; b=qUw9KZvIGqwDbNV9hFD1uwTursTQF0+TdDJplH2bRIUW643AyQBzi2XtpvvpPwzueP krTrOztlCpFTvc+hnhv1Oh03bLJ3f8bSPh0KzKOsPVk9ZhzKVXkjAMEQQKuhE4oBMzHz TO/CIXkmU68J2c+znitCj+FBgklgSsk2FqwJ3PlmyeSIVenHoiifB8NoFMNb9RrtL3B9 qcv4WAfneUHjj+843vVOOYYw0COdo/ombDoM/axiStrSjZSJUgLD2pfZEamFpnRACRBK mBJDavMvVU05d38c2NfZN/45X+0f+LDaojhLU/pZKe+t6r8cXlBHB1rQGfmCoYA80+by u8tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679933512; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FkLtaHCwb4+H4c96s1kPfDfzicrJaxUvZt9EyVW2Phs=; b=RARz7NMUO7Gt1dlaLVWmUbjCM8YYwKcJoJfB90UXjpJ0Ku9sLOoEbT2N2kGRuuyJIN Df8ZCx/fbUcdIuEvhLL33YYyiCRcoYB9A0sXIj/gi6307+Dk5fztYIXRXNJ6v1vkhji7 /cFqU3AuES0CU/OZvhkTUlOKQC5W+lxGYSQu79n9OG+eLSq7ZyIpxPeJ1sS5/NsXdMFr Qnta43hIqBtKc7EjcHruRyVKIWfgendGVpkpSJLjwf/rVn0g5PeLBp0D2vQFnQ0OUk90 dOU5UbP0MJDySn+bo6JFbrvwm26zikSR5Iv53HBqNVW0PYeByKvay06SXBNtCnjIks9i 6PsQ== X-Gm-Message-State: AAQBX9frjGC5PdmwpXAjDDBgTEDSV29JXZIKO0v0QRs1HW7Li5C5wf5v O3Ls0p5NTvUnjfqXU7Dc8iskfhp0JwF0ESKWqYVIwodTMSccG/Xehn1/maoON3kYDobZh3Wp8ib bhX8+H2agtaxH7vbWD2bFev0gMcWPOICZdSiMmDVcXKC92URaBKcxIj5a X-Google-Smtp-Source: AKy350Y0sQymwKuA15Sr5JqMgIy6MVkne5ECkVZtvP/4hKkR0S2QkJfjCEmNyAt4waGFCnI5C2IhvRYo3/Q= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a81:a805:0:b0:546:6ef:8baf with SMTP id f5-20020a81a805000000b0054606ef8bafmr341610ywh.2.1679933512380; Mon, 27 Mar 2023 09:11:52 -0700 (PDT) Date: Mon, 27 Mar 2023 16:11:43 +0000 In-Reply-To: <20230327161145.1702680-1-edliaw@google.com> Mime-Version: 1.0 References: <20230327161145.1702680-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230327161145.1702680-3-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v4 2/4] set_dev_loop_path: Change return value to zero on success X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" set_dev_loop_path was returning 1 on success and 0 on error, which is inconsistent with the other functions in this file. Change it to 0 on success and 1 on error. Signed-off-by: Edward Liaw Reviewed-by: Petr Vorel --- lib/tst_device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tst_device.c b/lib/tst_device.c index 82550dbcd..381b91554 100644 --- a/lib/tst_device.c +++ b/lib/tst_device.c @@ -69,10 +69,10 @@ static int set_dev_loop_path(int dev, char *path, size_t path_len) snprintf(path, path_len, dev_loop_variants[i], dev); if (stat(path, &st) == 0 && S_ISBLK(st.st_mode)) - return 1; + return 0; } - return 0; + return 1; } int tst_find_free_loopdev(char *path, size_t path_len) @@ -116,7 +116,7 @@ int tst_find_free_loopdev(char *path, size_t path_len) */ for (i = 0; i < 256; i++) { - if (!set_dev_loop_path(i, buf, sizeof(buf))) + if (set_dev_loop_path(i, buf, sizeof(buf))) continue; dev_fd = open(buf, O_RDONLY); From patchwork Mon Mar 27 16:11:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1761785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=l+1ekOZw; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PldBV14dXz1yYf for ; Tue, 28 Mar 2023 03:12:34 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6DE103CCDB1 for ; Mon, 27 Mar 2023 18:12:31 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 68F6E3CCEFB for ; Mon, 27 Mar 2023 18:11:56 +0200 (CEST) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 5479C2009B7 for ; Mon, 27 Mar 2023 18:11:55 +0200 (CEST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536a5a0b6e3so93770807b3.10 for ; Mon, 27 Mar 2023 09:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679933514; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3fViac9MbDWQILs9fDverAH1LFD8JQBYF2FQ7eBO5WQ=; b=l+1ekOZw5EdmzlKl08CiJQK37z2favY7FC0AhttTIb4dJYuTSLjk0k4uAGSAuL8gpn zloF6bFw9RNvSOJVLqDp4rTQ7Y6HD1Bf9Lm1cPPr6uu2oAbGP7wlbsFnyrgPHJGoP98l qJ1LGGVCKOaPH7ytuLUOolcwlcaaAcqOwW1EnKY2Mj3govdT7Qce/D/FAR822KgPxYJc 9F0dyIVLTvYwLFTAx+3PXV1XSHybySAAYOnQ1m3phcz5nXzT9UQ5yxlZ7PmlfZ+UCmr0 kpMt5bjDFrWY7KmUrO4132kAurJRwux713gWztfGQFRslDowCBmBHfYy1Wp01RH0F2IY 7GAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679933514; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3fViac9MbDWQILs9fDverAH1LFD8JQBYF2FQ7eBO5WQ=; b=t+cXz4T9Ampl4HTNoR1nn2vMFu0MrZNxcbY+JjpdimshwKfuzhCSgVscXcsqwMTeo7 0N8FxwUM+a9wRnqQrnHFMLm8o/FWS2qHITueLe8DltTi5oFjYPqTOnx+KT36rwM2UAgX r/5mMZ/pHTEFshIl26YPHGWBiQRsuXZ1DgLrox3OY4LxMUtaheaEO9YijPVZgNJMKFgQ 1Xou5xWnBBsdR39GC5JU9XuzYU61EDQyMyXNJkt8rbK26XlN0bEJp1dwOLub3Jjvx9cB btp6lmGyFy+lIzTUQH9i4liRUigGwsFE9356ftcbiioibWFm1solloTinVQDdrOiVeQE O8aw== X-Gm-Message-State: AAQBX9d2FOzM5t7N9EyKKTFoPDNxBRKwh4wjNp8fo8AZzD10mpVfZHvO TpfZgIihGEXo1mxan03TaX/bGR4bRc63YLTiySkJvhkeTVxsN0bxfGPcuz5yRljtUPm2WvXesVE GLuva+9D6CjYZlLOMd5fet/G7nKtYlwldUoP2eeEorGeJsKLUEqnsme5k X-Google-Smtp-Source: AKy350aOE8COwEv8apTjONwQC394jtX161rfn5Wa/luu7fmV+z4kO/CawUyYLclFj49RDHrnNrmCDw6m+Q4= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6902:1083:b0:b75:8ac3:d5da with SMTP id v3-20020a056902108300b00b758ac3d5damr5625197ybu.4.1679933514168; Mon, 27 Mar 2023 09:11:54 -0700 (PDT) Date: Mon, 27 Mar 2023 16:11:44 +0000 In-Reply-To: <20230327161145.1702680-1-edliaw@google.com> Mime-Version: 1.0 References: <20230327161145.1702680-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230327161145.1702680-4-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v4 3/4] tst_find_free_loopdev: Check return value of set_dev_loop_path X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" tst_find_free_loopdev does not check the return value of set_dev_loop_path and will return the last attempted path even if it does not pass a stat check. Change it to return TBROK if it fails to acquire a loop device. Signed-off-by: Edward Liaw Reviewed-by: Petr Vorel --- lib/tst_device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tst_device.c b/lib/tst_device.c index 381b91554..2b4b6fb95 100644 --- a/lib/tst_device.c +++ b/lib/tst_device.c @@ -88,8 +88,8 @@ int tst_find_free_loopdev(char *path, size_t path_len) rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE); close(ctl_fd); if (rc >= 0) { - if (path) - set_dev_loop_path(rc, path, path_len); + if (path && set_dev_loop_path(rc, path, path_len)) + tst_brkm(TBROK, NULL, "Could not stat loop device %i", rc); tst_resm(TINFO, "Found free device %d '%s'", rc, path ?: ""); return rc; From patchwork Mon Mar 27 16:11:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1761786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=MdxsCktD; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PldBk1tPsz1yYf for ; Tue, 28 Mar 2023 03:12:46 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EB6713CCD65 for ; Mon, 27 Mar 2023 18:12:43 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5D8F83CCD74 for ; Mon, 27 Mar 2023 18:11:58 +0200 (CEST) Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id ACECF1A00A28 for ; Mon, 27 Mar 2023 18:11:57 +0200 (CEST) Received: by mail-pl1-x649.google.com with SMTP id z16-20020a170902d55000b001a06f9b5e31so6170708plf.21 for ; Mon, 27 Mar 2023 09:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679933516; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Dq+u+hLzvFu1QO/mkJ3o+R8rp2fj58CwJfA8LZJICuM=; b=MdxsCktD0HiiAeXyCJQ9FymCm+Y6DdSCx8zFRybJk3HkuYh64jQ1xEWlEjwu202YeH zwbdCJvyZOLDlMJ0XeRILzfx/vG6idwK8KpygBY9dxdXK4mfFQqbKYLFuyHq1mPe/hH9 l7Qg8g0Y9Y/NuVlsJUPWDpPLONwot27UHIKTcq06F8nFnKXhdNyXr9bwGa4vIEuMORIR 79HcHCxwG+JDWFAz+nwP7LyQjUqvEv6CtKgy0FGxHOyAVZSj6skJ0PtJqG692P7jQmS/ cM8Pe4Mi361Jn8hKm20LZgXf7kEk8HIlWXd6S5AZdWhem+OBQV0ydbdPKPF7peQDWMew EQOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679933516; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Dq+u+hLzvFu1QO/mkJ3o+R8rp2fj58CwJfA8LZJICuM=; b=m+jAtGBk6JJo5hztC3eNycczEnON6xhN09mxHhYShPQ+ab4NcphAFpgbb4TLJEgJLo y5kpbh9sOwtMx/popqLuvd0nMaX7T3Ftw6rHw61PdgvwKxDZLxbimO9TKL0Vy2yH2SKX dBl6B7zQC2wNBabPWWneecJjwf8B5o6xDHxnUfhR4zDJ+0E95yuVGQH7bbABVSlg86+0 mluP9l9UbpfOD5rMXIuhhCuX+55RHfk62ehsei+k22vktPMfhuG3R3LWpKql8wiOFVAv YCR5q7ZwPxIZ4+yNdIETQE0BIBZIwkpIf1jJxcyrb1YBqpVFsmlV1UzRTU+0lVXBLFL1 bhFg== X-Gm-Message-State: AAQBX9drhI8979R9Ql/M0dHTdHreTCFkoVuKNCSyiJujpdqFR9cHXSp1 +WLwL6QvBYRjcYR0GO+5oLPHWYMLLpz6gqCB3EOf1+/CDPazzjSj8WF8BOhyXXLU71N/OJ1tSAb R5KE4a6HmRY4OFHADM5xEaKownPro1vNWxncqMv6j+Zuz7Cts/n7YnNK9 X-Google-Smtp-Source: AKy350Z6f2hCMlD3MNTL24/KShixYKPrdnr0mMs3RPXNUOPdJ5c2q6q94YtI6yqKyJrwy1WR+aQdETIK9WQ= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:1881:b0:625:d7e6:51a0 with SMTP id x1-20020a056a00188100b00625d7e651a0mr6784863pfh.1.1679933515951; Mon, 27 Mar 2023 09:11:55 -0700 (PDT) Date: Mon, 27 Mar 2023 16:11:45 +0000 In-Reply-To: <20230327161145.1702680-1-edliaw@google.com> Mime-Version: 1.0 References: <20230327161145.1702680-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230327161145.1702680-5-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v4 4/4] tst_find_backing_dev: Also check /dev/block/ for backing device X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Fixes: e1b1ae66b240 ("tst_find_backing_dev: Get dev name from /sys/dev/block/*/uevent") On Android, the backing devices are created in /dev/block/ and will not be found using the method added in e1b1ae66b240. Adds a check for /dev/block/%s as well as /dev/%s. Modified the function signature of tst_find_backing_dev to add the length of the dev path string. Updated the documentation and code that references it. Signed-off-by: Edward Liaw Reviewed-by: Petr Vorel Reviewed-by: Cyril Hrubis --- doc/c-test-api.txt | 2 +- include/tst_device.h | 7 ++-- lib/newlib_tests/tst_device.c | 2 +- lib/tst_device.c | 37 +++++++++++++------ .../kernel/syscalls/ioctl/ioctl_loop05.c | 2 +- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt index a7dd59dac..11f87def2 100644 --- a/doc/c-test-api.txt +++ b/doc/c-test-api.txt @@ -1087,7 +1087,7 @@ is created for that intention. ------------------------------------------------------------------------------- #include "tst_test.h" -void tst_find_backing_dev(const char *path, char *dev); +void tst_find_backing_dev(const char *path, char *dev, size_t dev_size); ------------------------------------------------------------------------------- This function finds the block dev that this path belongs to, using uevent in sysfs. diff --git a/include/tst_device.h b/include/tst_device.h index 977427f1c..39545fab0 100644 --- a/include/tst_device.h +++ b/include/tst_device.h @@ -108,10 +108,11 @@ void tst_purge_dir(const char *path); /* * Find the file or path belongs to which block dev - * @path Path to find the backing dev - * @dev The block dev + * @path Path to find the backing dev + * @dev The buffer to store the block dev in + * @dev_size The length of the block dev buffer */ -void tst_find_backing_dev(const char *path, char *dev); +void tst_find_backing_dev(const char *path, char *dev, size_t dev_size); /* * Stat the device mounted on a given path. diff --git a/lib/newlib_tests/tst_device.c b/lib/newlib_tests/tst_device.c index 87cec3961..53099f9bc 100644 --- a/lib/newlib_tests/tst_device.c +++ b/lib/newlib_tests/tst_device.c @@ -71,7 +71,7 @@ static void test_tst_find_backing_dev(void) { char block_dev[100]; - tst_find_backing_dev(mntpoint, block_dev); + tst_find_backing_dev(mntpoint, block_dev, sizeof(block_dev)); if (!strcmp(tst_device->dev, block_dev)) tst_res(TPASS, "%s belongs to %s block dev", mntpoint, diff --git a/lib/tst_device.c b/lib/tst_device.c index 2b4b6fb95..892e0b2e6 100644 --- a/lib/tst_device.c +++ b/lib/tst_device.c @@ -60,6 +60,11 @@ static const char *dev_loop_variants[] = { "/dev/block/loop%i" }; +static const char *dev_variants[] = { + "/dev/%s", + "/dev/block/%s" +}; + static int set_dev_loop_path(int dev, char *path, size_t path_len) { unsigned int i; @@ -75,6 +80,21 @@ static int set_dev_loop_path(int dev, char *path, size_t path_len) return 1; } +static int set_dev_path(char *dev, char *path, size_t path_len) +{ + unsigned int i; + struct stat st; + + for (i = 0; i < ARRAY_SIZE(dev_variants); i++) { + snprintf(path, path_len, dev_variants[i], dev); + + if (stat(path, &st) == 0 && S_ISBLK(st.st_mode)) + return 0; + } + + return 1; +} + int tst_find_free_loopdev(char *path, size_t path_len) { int ctl_fd, dev_fd, rc, i; @@ -512,7 +532,7 @@ unsigned long tst_dev_bytes_written(const char *dev) } __attribute__((nonnull)) -void tst_find_backing_dev(const char *path, char *dev) +void tst_find_backing_dev(const char *path, char *dev, size_t dev_size) { struct stat buf; struct btrfs_ioctl_fs_info_args args = {0}; @@ -575,7 +595,7 @@ void tst_find_backing_dev(const char *path, char *dev) sprintf(uevent_path, "%s/%s/uevent", bdev_path, d->d_name); } else { - tst_brkm(TBROK | TERRNO, NULL, "No backining device found while looking in %s.", bdev_path); + tst_brkm(TBROK | TERRNO, NULL, "No backing device found while looking in %s.", bdev_path); } if (SAFE_READDIR(NULL, dir)) @@ -591,17 +611,12 @@ void tst_find_backing_dev(const char *path, char *dev) if (!access(uevent_path, R_OK)) { FILE_LINES_SCANF(NULL, uevent_path, "DEVNAME=%s", dev_name); - if (dev_name[0]) - sprintf(dev, "/dev/%s", dev_name); + if (!dev_name[0] || set_dev_path(dev_name, dev, dev_size)) + tst_brkm(TBROK, NULL, "Could not stat backing device %s", dev); + } else { tst_brkm(TBROK, NULL, "uevent file (%s) access failed", uevent_path); } - - if (stat(dev, &buf) < 0) - tst_brkm(TWARN | TERRNO, NULL, "stat(%s) failed", dev); - - if (S_ISBLK(buf.st_mode) != 1) - tst_brkm(TCONF, NULL, "dev(%s) isn't a block dev", dev); } void tst_stat_mount_dev(const char *const mnt_path, struct stat *const st) @@ -644,7 +659,7 @@ int tst_dev_block_size(const char *path) int size; char dev_name[PATH_MAX]; - tst_find_backing_dev(path, dev_name); + tst_find_backing_dev(path, dev_name, sizeof(dev_name)); fd = SAFE_OPEN(NULL, dev_name, O_RDONLY); SAFE_IOCTL(NULL, fd, BLKSSZGET, &size); diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c index b4427f331..3a5d5afef 100644 --- a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c @@ -125,7 +125,7 @@ static void setup(void) * needn't transform transfer. */ sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir()); - tst_find_backing_dev(backing_file_path, bd_path); + tst_find_backing_dev(backing_file_path, bd_path, sizeof(bd_path)); block_devfd = SAFE_OPEN(bd_path, O_RDWR); SAFE_IOCTL(block_devfd, BLKSSZGET, &logical_block_size); tst_res(TINFO, "backing dev(%s) logical_block_size is %d", bd_path, logical_block_size);