From patchwork Fri Mar 24 00:24:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1760581 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=DrM1dD1N; 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 4PjNJN5LrTz1yXv for ; Fri, 24 Mar 2023 11:24:52 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 91EE33CE2EE for ; Fri, 24 Mar 2023 01:24:50 +0100 (CET) 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 [IPv6:2001:4b78:1:20::5]) (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 picard.linux.it (Postfix) with ESMTPS id 8B7DE3CD349 for ; Fri, 24 Mar 2023 01:24:48 +0100 (CET) Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) (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 D19B0600473 for ; Fri, 24 Mar 2023 01:24:47 +0100 (CET) Received: by mail-pj1-x1049.google.com with SMTP id b1-20020a17090a8c8100b002400db03706so30175pjo.0 for ; Thu, 23 Mar 2023 17:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679617486; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pOlRspFVkCYibR2WLa25T78Sman5B5V9qSwkUIygy68=; b=DrM1dD1Nxk2nHxW5vG6oXxNgWWEORUNL5NkNZw1OOckoFOig/g7EcqKo5DH9SVok1d gQ9FRrhzd0tC5P8G6JEfWK4umRSwK4/4bDq9GNXs/tReavzr3jUNiOHXQ7pKmUxTzWfd pN0AX06xVnPM3Zvofqo5v+zBFcuupCXBr10XZTYI66SDK+yze6XmJaAVNwjJyESWg/8L m8OFgu4wm1hMKGpbfwIFvjI5PQ2Xdbx7BSBtOlG7UU58SmJiDWdVvNnJSGNCq5fbb0rq YFRnd2o9dnvaCaSLYeneteXHUCj5PHpW0C0Y6nw+2mAd0ItQSWTKB/fSMXEHKL44q5ND DTAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679617486; 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=pOlRspFVkCYibR2WLa25T78Sman5B5V9qSwkUIygy68=; b=Vpx1XNylNYZ1u1RuKakfsHAT12E6LS918ZhFSDcoGzIoVYffMLKsqMi5K4I98X8oBY jibEdHeovXVidrSaD2/MiQXGvEfz+9pGEVVuQBlXybV0aBPTEQ/kpIkXfoIA7OOM+1sJ Xl0lPm/rFFZNAFc8O1+IVCtoIh4XtSLpfb/Xw9vtf7TLUApUCs5vKJgaPpi+HP0uaV0C 6jt6ZwFWAQ9FV2Ba8l9g9s869aKOiz75wc6wYgnHiM5PbvXdA+gOWr7JqnGHHVSrZaRC Lb+kjIjukh1kH1oByO3MalRqzjYj/X8rvmyM8Ao7ol4IZESaGTqwrqj+BBzAgUsRYaeK Y+5w== X-Gm-Message-State: AAQBX9cXl4s6YpYV9hgPqhp88lIB00nSrEx4Zgft+wIbDL112r8Zlzom FTuEjgPxsriIw7CLWvTHpxJZXXqPqH4NaZem2R5qZDYYYhw2ii809KH//5ICwFK2JS7iNNGtXfD f4hY6T1KpWSJYnXS87JQEgkSWAWkVnRCNprb/bPHSvHtPiQD1VjkWCHGw X-Google-Smtp-Source: AKy350YC1LG46dXjNncgXITQLCETy3KECS4TucAuc/HoSrJZ5H5SuxCfeE5BygkFAYRhLIN8j2nOqciUNF0= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:10ce:b0:622:65cc:d87b with SMTP id d14-20020a056a0010ce00b0062265ccd87bmr632367pfu.5.1679617486079; Thu, 23 Mar 2023 17:24:46 -0700 (PDT) Date: Fri, 24 Mar 2023 00:24:38 +0000 In-Reply-To: <20230324002441.987778-1-edliaw@google.com> Mime-Version: 1.0 References: <20230324002441.987778-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230324002441.987778-2-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 v3 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 a61c5a748..5d057570c 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 Fri Mar 24 00:24:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1760583 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=klUu2Qct; 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 4PjNJq4DPxz1yYB for ; Fri, 24 Mar 2023 11:25:15 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3A8F03CE2E9 for ; Fri, 24 Mar 2023 01:25:13 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (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 picard.linux.it (Postfix) with ESMTPS id 4F7853CE2E7 for ; Fri, 24 Mar 2023 01:24:50 +0100 (CET) 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-6.smtp.seeweb.it (Postfix) with ESMTPS id B548C140053C for ; Fri, 24 Mar 2023 01:24:49 +0100 (CET) Received: by mail-pl1-x649.google.com with SMTP id d2-20020a170902cec200b001a1e8390831so249582plg.5 for ; Thu, 23 Mar 2023 17:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679617488; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Tetz773QhDFSbXijMu+8e89BLyLkE2x3msPixKxSDuY=; b=klUu2Qct0ISG3fbMivocfVv1+lN9AkHCXR/LRXXMQGln4A1t5zQQgqhkARWyxXFvs+ 2NygCAxn+xyYbp6sGPyqa5ZLBJ2LxufxebzlV8oh71NW8LmJL7ML2Ku52gC2CMBestHQ PkaXcm3mynlentDpWlZI8xtDg1zkU3AzjYWMHAMFmo5NRF3P2rdCXApeN43fvLsvVcL4 wsY4bMlI4Ss87Qxv9nAbll+IDLSGCOAn6YspX6MlezAHrJPbyPKOV6iwsU8MWLjxKCku HcTMgWiqg2Wz6gMyXBp4Hgz4GciIgGCq+EKpfX3xb/aBwOttG2j6p1Kw3Eh6pZ/Eq5p2 APIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679617488; 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=Tetz773QhDFSbXijMu+8e89BLyLkE2x3msPixKxSDuY=; b=PP4UHv8utKk78niHL254jBIuoqIWMwYap9djVEdeGYxOBLRC5Z8dp4il1JiVhOrjvL sJ4SgAEVEhUBOQKy5UH0g4GmwUgOh0aX+H7RcR0fbEl0bVWr3FV55db+rpgX2y2A7YWv laydVocIiclnxCisnJBd6pq2raZN1UovhxAMMkrlsSqkbgjfxzZiIFlWyJdSQGYOweRn ONQHBWt9VndE+pmHFPzbTO0eU85imSN+ub7QI4TiQccyl3AQcr+TW6tQV+8quP55x4tQ XzHmeIOV79xsjnJaQ8nln43rmVots8BSW5lTvtWog0ZjW2/aN1+Bxfb65ySSdUFlEhdn yVMw== X-Gm-Message-State: AAQBX9dt6r5623kmtExkazEFT3Xb0qAV056IPGj2Wz3JsFClN+PsiKPq gfFNnHyfy1pqsdFUMsEykG0EuHZblF4QKHEbW9S7llT1u5i4aPFV/7ZJLa9wGnOl3zXrXwq67A1 PinV80M70KXlfCl7W3BbB5rgC4uDOf9JaEAjNWJhjVWfWncj8/GJXyTCx X-Google-Smtp-Source: AKy350Yxx+aUMUPf8xYCZTEV5ZlCZFzqG4TiGzb1Yb3E1Ci/BQSwFgLsfHTprNF8/ImhZ7s65Kfn9/xTVYw= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:1a46:b0:625:c7de:48c1 with SMTP id h6-20020a056a001a4600b00625c7de48c1mr651156pfv.4.1679617487918; Thu, 23 Mar 2023 17:24:47 -0700 (PDT) Date: Fri, 24 Mar 2023 00:24:39 +0000 In-Reply-To: <20230324002441.987778-1-edliaw@google.com> Mime-Version: 1.0 References: <20230324002441.987778-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230324002441.987778-3-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-6.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-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 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 5d057570c..2c83fb764 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 Fri Mar 24 00:24:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1760585 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=QWm+qKwT; 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 4PjNKG4jkkz1yYB for ; Fri, 24 Mar 2023 11:25:38 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CF7D23CE2FA for ; Fri, 24 Mar 2023 01:25:35 +0100 (CET) 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) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id DD92A3CE2F7 for ; Fri, 24 Mar 2023 01:24:51 +0100 (CET) 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-3.smtp.seeweb.it (Postfix) with ESMTPS id A49C01A0042A for ; Fri, 24 Mar 2023 01:24:50 +0100 (CET) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54196bfcd5fso2774437b3.4 for ; Thu, 23 Mar 2023 17:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679617489; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5VR42ibL4bf5gSYfsByt/kf/pPpCCWkTIyxpPWoGn3g=; b=QWm+qKwTMIJgoHMjvGu/wiKAjBTtWQHTzy/NKlmnbju4s89yQQYaaGr7sgvmii7uQ1 xzfeRrGYJq2YXeOyJQ3DB7hC5tCrxSUBU5lRlOiBlY0FEu5LFraQmc6vB3byloWcjnql eVLSv0Oc+av7C4OdFLB8a3PWImumoOSdqblMZrcGUsSGrf1vT1xxQPsTUP9WKZ2hElQq /u5N7bBPJeaRLP1YTqSnncUCwpWGQhDj/VsJRIV+v8yW9mx9+mA3ljcrJCQV5VkPe7iK eg7qEPfnfmWuZzzZyuhq7LqSgvo8yXc7lXeun+phYTBKk8HwTwkzk/MmdHocGUAbSl2z ljNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679617489; 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=5VR42ibL4bf5gSYfsByt/kf/pPpCCWkTIyxpPWoGn3g=; b=4317xfqWRDP51UIGUIy9xScBzdeK4E/NgnqUrKJFbhEGz9SQlZUrtyZMHLGYCyWp3T qlpi3Ovq/O5ugftuHIHGEj7ZusjRoXdzRQ7NOBxJI42ugluyiiUYmVKHbSLQAvnlI8Ya JjmqcG6o0Z40ge9N4RU8YfiBckx+unSmiAN0nZZuXHhp94Dan2jrv4UeRsDgG0SV9uVK Z81gj7PMrBpZwMot3bZc0IrLur+Gh2oS5FVtVKFsJysFe3kQ4BoV8IYwS/SWvNOUuncZ 08rLWZQhcVE7f6Ug6EpAMghkK8HS0AodSq44EaERcZbhMe6Be94KPuRYUA0x2XGjKUuU QWRw== X-Gm-Message-State: AAQBX9cKKW0jLfIO8J+9ILp79ZUapHcngNBKpmcs/sgBD1k5c6UbIE1u HUUsoSOnBb52T9b6Qd6UtODCqsYDvM4zIS07mCwb/HqKaWzzlMW0oWHcyund7hXTou1rrrG64Sx hqrcl6sbYeTFxeIENuIfUr+yeH7XOpeeiuRPgpjdioOJTaMBzcISu738S X-Google-Smtp-Source: AKy350Z/56T64chThNMxXkDLIWh7QbrmAP9oUzcxEgdICOLZ/efyNsPtHV2WN/kJBpWhRKBZMHtL8LznVjA= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a81:b50f:0:b0:544:b8d8:339e with SMTP id t15-20020a81b50f000000b00544b8d8339emr204294ywh.5.1679617489485; Thu, 23 Mar 2023 17:24:49 -0700 (PDT) Date: Fri, 24 Mar 2023 00:24:40 +0000 In-Reply-To: <20230324002441.987778-1-edliaw@google.com> Mime-Version: 1.0 References: <20230324002441.987778-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230324002441.987778-4-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 v3 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 2c83fb764..ba46b7613 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 Fri Mar 24 00:24:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1760584 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=qqfCKttL; 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 4PjNK22m8nz1yYB for ; Fri, 24 Mar 2023 11:25:26 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 64BD23CE2FF for ; Fri, 24 Mar 2023 01:25:24 +0100 (CET) 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 [217.194.8.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 C2A833CE2F5 for ; Fri, 24 Mar 2023 01:24:53 +0100 (CET) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) (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 F12AF200389 for ; Fri, 24 Mar 2023 01:24:52 +0100 (CET) Received: by mail-pf1-x449.google.com with SMTP id x68-20020a628647000000b0062624c52117so191234pfd.14 for ; Thu, 23 Mar 2023 17:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679617491; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dozakL9iauduyGN1pW1ynBMWErkfMph17QNZZsx5zek=; b=qqfCKttLy15gLeWMTift41owzAmvFRmoBX8x0SjrSnUEIYLtpi8yNPGoaDoWiRwd9h 2J3a/UuBqQJjgpMzglHjTCEhRc+8+PolbccFsqP/DTzA/bIa9vJtLiSHLJ/k8YK9oCGJ t2xDWHAuePWDWiFO0XNe/nGySmmxzYOh9iLHL2Go3kp5GLjZzei/qze+qZ4nWY/QtVAX s5XT4kdmHCjmwxJqr54/l1IZfQVPeg2hUXMXClBcnMJDmKKmcUDe9hwF/FwT7ISib2iP ctk2HIXMRb7W+Nk1pMuZeLeUrSd7HhwhovQJf3Sv5XbtyMz4L/2xBL9E9j00lLQeMXWR g8jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679617491; 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=dozakL9iauduyGN1pW1ynBMWErkfMph17QNZZsx5zek=; b=Srr7ojiGtslifGpq0T51sSkFKKMWAT1x40tpVVzm0l2Eeu1Q2PxpCFmVYe6f4E4gb+ GbMCxMHuUNMHfMPf9/X2pYNqTPAQqFTJHCpc9mzaBHD0BMu9PquPwESBqjEwVHVdDm84 NCl0wIGsZ+whJdZqHpdB173VR7au0woBYfIL373kHYeig3bQU7tuEItAd0SO2BDQb/2a NM09ZJ9a7y9xbI7mQypvShM9Akurj00kgEPSELg2lnScaSUtWrLV4wyOWxkbldWzQAPn Qynf1khstTYEXRPD2drEgdK73GXFdBFphzAWxIV3/hpjoTZU1y5Aaw+pUrt1QzGwSeXr Xk5g== X-Gm-Message-State: AAQBX9cWXEmgzSYT2Fc5r9eeqyjUU03sR6cv6SLciwr9EcCI5NzMvuED Tvj6gUPBw7zDscQA8EZzGLwQ65Vb8vExEk1kA7B3Yl1afcqTtEdMp1LxTHB19QgvN5TPGFm0YQu XU1o7dTfYAJ8wjdnB1wAb68ejPMj7uXpywib5jMzZ1n8PTK/WftKvsLCk X-Google-Smtp-Source: AKy350bNk+G3paa7qGNOanEG66dHOeDQUnk4I9UHPKyoGahITSgl3YyVya46kjg04Uvp6xxS1+j1+SRLpIM= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:903:684:b0:1a1:ba37:d079 with SMTP id ki4-20020a170903068400b001a1ba37d079mr2868367plb.3.1679617491273; Thu, 23 Mar 2023 17:24:51 -0700 (PDT) Date: Fri, 24 Mar 2023 00:24:41 +0000 In-Reply-To: <20230324002441.987778-1-edliaw@google.com> Mime-Version: 1.0 References: <20230324002441.987778-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230324002441.987778-5-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 v3 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 | 3 +- lib/newlib_tests/tst_device.c | 2 +- lib/tst_device.c | 37 +++++++++++++------ .../kernel/syscalls/ioctl/ioctl_loop05.c | 2 +- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt index a7dd59dac..eddb5c893 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_len); ------------------------------------------------------------------------------- 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..f0aff4473 100644 --- a/include/tst_device.h +++ b/include/tst_device.h @@ -110,8 +110,9 @@ 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 + * @dev_len The length of the dev string */ -void tst_find_backing_dev(const char *path, char *dev); +void tst_find_backing_dev(const char *path, char *dev, size_t dev_len); /* * 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 ba46b7613..74de307e7 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; @@ -511,7 +531,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_len) { struct stat buf; struct btrfs_ioctl_fs_info_args args = {0}; @@ -574,7 +594,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)) @@ -590,17 +610,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_len) != 0) + 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) @@ -643,7 +658,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);