From patchwork Mon Mar 20 22:37:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1759244 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=X1De4e7o; 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 4PgV4C52Xzz246f for ; Tue, 21 Mar 2023 09:37:47 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4CFC73CA84C for ; Mon, 20 Mar 2023 23:37:45 +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 B3C1D3CAB99 for ; Mon, 20 Mar 2023 23:37:34 +0100 (CET) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) (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 27E8A2005DA for ; Mon, 20 Mar 2023 23:37:34 +0100 (CET) Received: by mail-yb1-xb49.google.com with SMTP id w5-20020a253005000000b00aedd4305ff2so14552856ybw.13 for ; Mon, 20 Mar 2023 15:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679351853; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4Fas2rakiukDaDdeltWCU43sJnn/oSNsrkv4SQGpOHY=; b=X1De4e7oOA1Aa/DPU1sRFd/viNJqDyUaNzRvm3RTWOId2F3Xqy3qgsY/IklSG9Z+NQ Xl65TpOyn0lSJ/PWFPIDicnwUcRTVksNdj09hLA2FvLEN8VmhxevXfOOQ8tel/GDn/E1 OAjQmPpgE3xTuHK5esOS8y4P49+g8XY9CYJjxu9RLrWuRi9eujM4g6t/vSXUe+v1IORd 2mWCIyU/nmY+uxKXy4j4uKY613TiPxzG1CkABKH8BHRF+sBOeyce19Zs0/zvD6SHryQv P3l/hk0qXzT/zhMmfLUiTdMKXYjVOKBrHSSF3RmM+8MeYhQ7bzq1WHOe3VCPf5UbI3+w 4Mag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679351853; 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=4Fas2rakiukDaDdeltWCU43sJnn/oSNsrkv4SQGpOHY=; b=hISmkv0P0G2ZZ4SzJ3u8+kK7GpBPcR6u0UEaa9bd3MhPKSaKXjyTXSCVtsgvNyGDwV M7C4eaAlmflHwIBHSkOGXFB7rLQANs51PeLexigWdpaaa7NDtUnSIy2udQMkCV6F/OJ9 5Mzw5eo7TgHVc4OmVA7B3CBEskPiLIDgh6T0x1QfLApAH3L52943W+JUUv7NxHXy2YVw qDr88i7YTjwAabbq9yrLwh7NYJ3g/JaSwwOuvFU05YQzf/i6TCoBa2rqwiyZ3Qsklusy HKnvitAj7iofJ/TUQOzrLddi3MZ9f4okspoWTCwNxFJt90qzEutiUleYArVF8jW1A7Sq QizQ== X-Gm-Message-State: AAQBX9c8kNJILSes9OWMqZDCmzZlbU64MI7d7fGHs4Jm0W5Puhpva+Xh WPRtUd7IpTBFt4uABtu2nmCjrAUSD+xCxR/vCilZ867rbGh2D20ftFmuYqOaNBGUHqOG9wQoAml whTy+IvOEDO73SIs70IHWzDoN4tI3nYlCSDaeZ00kw3pxmPfJaoj5qrIA X-Google-Smtp-Source: AKy350bVn1bCfFA2TdJ+Jv3b8CvOABcZV1KOQNlANHz6NWCbc2fvpiInj2p5sWKu6Czj5+5FBXezw5WQx+s= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6902:708:b0:b6c:2224:8a77 with SMTP id k8-20020a056902070800b00b6c22248a77mr146495ybt.1.1679351852818; Mon, 20 Mar 2023 15:37:32 -0700 (PDT) Date: Mon, 20 Mar 2023 22:37:21 +0000 In-Reply-To: <20230320223723.2030960-1-edliaw@google.com> Mime-Version: 1.0 References: <20230320223723.2030960-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230320223723.2030960-2-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 v1 1/3] tst_device.c: Use PATH_MAX more consistently 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" Replace hardcoded 1024 path sizes with PATH_MAX. Signed-off-by: Edward Liaw --- lib/tst_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tst_device.c b/lib/tst_device.c index 48d7e3ab6..a61c5a748 100644 --- a/lib/tst_device.c +++ b/lib/tst_device.c @@ -50,7 +50,7 @@ #define UUID_STR_SZ 37 #define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" -static char dev_path[1024]; +static char dev_path[PATH_MAX]; static int device_acquired; static unsigned long prev_dev_sec_write; @@ -79,7 +79,7 @@ int tst_find_free_loopdev(char *path, size_t path_len) { int ctl_fd, dev_fd, rc, i; struct loop_info loopinfo; - char buf[1024]; + char buf[PATH_MAX]; /* since Linux 3.1 */ ctl_fd = open(LOOP_CONTROL_FILE, O_RDWR); @@ -489,7 +489,7 @@ int find_stat_file(const char *dev, char *path, size_t path_len) unsigned long tst_dev_bytes_written(const char *dev) { unsigned long dev_sec_write = 0, dev_bytes_written, io_ticks = 0; - char dev_stat_path[1024]; + char dev_stat_path[PATH_MAX]; if (!find_stat_file(dev, dev_stat_path, sizeof(dev_stat_path))) tst_brkm(TCONF, NULL, "Test device stat file: %s not found", @@ -641,7 +641,7 @@ int tst_dev_block_size(const char *path) { int fd; int size; - char dev_name[1024]; + char dev_name[PATH_MAX]; tst_find_backing_dev(path, dev_name); From patchwork Mon Mar 20 22:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1759245 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=GdQwmhaR; 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 4PgV4Q4SsHz246f for ; Tue, 21 Mar 2023 09:37:58 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 63F863CAA88 for ; Mon, 20 Mar 2023 23:37:56 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (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 BCDD93CACD8 for ; Mon, 20 Mar 2023 23:37:36 +0100 (CET) Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) (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-4.smtp.seeweb.it (Postfix) with ESMTPS id 0CF5C1000772 for ; Mon, 20 Mar 2023 23:37:36 +0100 (CET) Received: by mail-pl1-x64a.google.com with SMTP id z14-20020a170903018e00b001a1a2bee58dso6706691plg.3 for ; Mon, 20 Mar 2023 15:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679351854; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pi6ZbuljnlMIkXomu9Dc1K6gA+NTa1EUTD4h4S/0Xms=; b=GdQwmhaRPd8hZjpPE+25+wvIb67vuUsWMZYROF5ReYBSWTxoVbV/mp69jZ4gIpRD5y 7DJ0ujnybE9XfDK2p2AJwNh41aTkv9LSrnUrcJk8wW91+DYMDn7N0qMWZN5s/f6uu7gz QAulrhdm1jTVK19SRUI4ZJt6XGYgTQL0fFhvXB18EQ/zFsHEIQsy2xmaV4zzroHi/Axw Dfd+0upHRKMz9/d+0+02TMGJmQfL6OcKKYxjsDtdd8/d4HQdxlBISMxi/oeISPRNMH/M fU/7y9ae0WWTJPMfdTkoEbULqpdO1flki4WMxgB8tRtmKVhexhSiCCTCLMsObVztum4n hxRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679351854; 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=pi6ZbuljnlMIkXomu9Dc1K6gA+NTa1EUTD4h4S/0Xms=; b=6N9CWHrbay1gmQD9KdzhDOYtfPtnyAwX9Bb3Q4NvHGj9g5k7dKgEwIvxmmrTVfG6gb eSBENX49zvGqlFpItn4k0svrraTirfvRPZVBuPQ84MvQxdcMuobqFYtRU/qxEbJUTvUV Tk9Y3YxZ+B4dUPBf7R1KnhHm5Ri1LSXr4sDx6RNW8a5JCRHx9KILIAvO//FbwnNsR6zD iBPm8AcdWdDHC5yj6+A8bpolc8dpJYHeh7UA9JvM/4JlBTDxxBclqOP0XwqIYpPN4ry/ /j2c8+/sqP8ooqOe6MMFMHnHFFGzQm5AFPJu9wf55Gimjvyt8/i2j5rQ8f3VDindrwAv 83cw== X-Gm-Message-State: AO0yUKV1sIX9m1UB4BR+9BB4mWGAJf/7T7dZldvcKy7dSW5pYgGpVAxS zNJsTGYJh1h3BvYqVv/ibMzi3ZN5cJDGAj6brfO2YmzPE8h0HxxJmsUTTLgTE9kKTgHetq85TRn Qomc3AZv0pe1h6zm5CZJS8TW9szWz/z3IGujtIVkA8uhi5AozO0FibqfC X-Google-Smtp-Source: AK7set9WIhsa9SLtY50StgTg+GNTJXiBGc45V5KS6lCD8/r/e/fnri3tGVEP4oBhTNMX2L3j3JP9mS6OGsA= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a65:4501:0:b0:50a:592b:25ba with SMTP id n1-20020a654501000000b0050a592b25bamr82345pgq.3.1679351854486; Mon, 20 Mar 2023 15:37:34 -0700 (PDT) Date: Mon, 20 Mar 2023 22:37:22 +0000 In-Reply-To: <20230320223723.2030960-1-edliaw@google.com> Mime-Version: 1.0 References: <20230320223723.2030960-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230320223723.2030960-3-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH v1 2/3] set_dev_loop_path: Refactor set_dev_path and check return value 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_path and will return the last attempted path even if it does not pass a stat check. set_dev_path also has a return value that is not consistent with the other functions in this file. Renames the function to set_dev_loop_path, the const array to dev_loop_variants and changes the return value to 0 on success and 1 on failure. Check the return value when called in tst_find_free_loopdev for failure to acquire a loop device. Signed-off-by: Edward Liaw --- lib/tst_device.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/tst_device.c b/lib/tst_device.c index a61c5a748..ae665f7b6 100644 --- a/lib/tst_device.c +++ b/lib/tst_device.c @@ -54,25 +54,25 @@ 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; + return 0; } - return 0; + return 1; } int tst_find_free_loopdev(char *path, size_t path_len) @@ -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_path(rc, path, path_len); + if (!path || set_dev_loop_path(rc, path, path_len) != 0) + tst_brkm(TBROK, NULL, "Could not stat loop device %i", rc); 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)) != 0) continue; dev_fd = open(buf, O_RDONLY); From patchwork Mon Mar 20 22:37:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1759246 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=tSpV3Vwv; 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 4PgV4d3fxHz246f for ; Tue, 21 Mar 2023 09:38:09 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8E6F93CAB97 for ; Mon, 20 Mar 2023 23:38:06 +0100 (CET) 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) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5090B3CA941 for ; Mon, 20 Mar 2023 23:37:39 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id E41DC6001EA for ; Mon, 20 Mar 2023 23:37:37 +0100 (CET) Received: by mail-pf1-x449.google.com with SMTP id b8-20020aa78708000000b005eaa50faa35so7000976pfo.20 for ; Mon, 20 Mar 2023 15:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679351856; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=efKpFrdGt03RhHy7C8l15+e39IZMCMLFT+ooej12Gso=; b=tSpV3VwvbYIt+p84WPafr9B9au2UX9VBMbRl4o1Ug/+Op7XU6qUTookL/Ep+Gkb1Pb h6pdfUbuiblyiJCuiKbtL7DQ0tpOedPix/TTNpIDi6zd9rT8PqQ8FJtlLJQpIhHfqpJN ho2yzcbAeUazl1U23dYirS3snN9MddubRfQYF6e7UuR+0NEq2BXGRJ2HZNoFgD+k/2WI XR59x4CImE3M22V1BqrSqBNJJOC44oueFvYb21QukdcsME6HUItt8wzu5JKfP/DwLC/f n35nq9F73ait0Gzi98Vp0PDL5SxQLbg2vF1KkwyzDH6zbcQrWK0UrjZwwJ+Jfusn9vfC FFlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679351856; 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=efKpFrdGt03RhHy7C8l15+e39IZMCMLFT+ooej12Gso=; b=7HBHIZc6noyu1Zlxi3H3NACud29kS10WT1LD3+tjKzikviPsMLjOOQwFp61JUFVb9t eXZhvMXpZbNYEW8RJmFqWdgcABezEJWZVOSzk2SRzkIEjfygR3D4Q0PlJPQ1cj0J4gTP JN34YdZrPekEkgLI6ktgRbGzsSWfn2AvnwWVdTC461zoEMC6e5Y5iadUmeVv052Qbogj 2fn+6XBj4LJMl5FzgsCOb/K3PSeQb8DSZxjwqvur+vooz2B5eM9ioo6wOg5x4ukwicCl CDIQGe2J5Gsp1N28nKT9AVWbUXhrK5muZ1CiIoArCPbnsfrfNGDypKRvzbwZWWR5z0vK PaHg== X-Gm-Message-State: AO0yUKV6RDmppcA9jJxRBALWRnDwO5e6IiqSTX2JmYjF0MEW3lA/jyNZ llODIF43Q83l3fK48EeeII1pOqoDkrxXgxKg6iCL8D8sa/SSirmXSdFiSJZMCmnaxGQa6vvMtvS Bz9cPqGCHkQqTZb4ZRxDrDZDVP9cVx4K5IwZ+NrvnSRC8UXW68G9hLYHx X-Google-Smtp-Source: AK7set8czHkaju4lMAHK1MzzPdmgFE0NZpZs+CD6w1Fnow+eJpNXWgy4jEgdxHsS9OLRjMTsTuP+OGu8naM= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:903:2594:b0:1a0:53af:58f6 with SMTP id jb20-20020a170903259400b001a053af58f6mr21074plb.1.1679351855972; Mon, 20 Mar 2023 15:37:35 -0700 (PDT) Date: Mon, 20 Mar 2023 22:37:23 +0000 In-Reply-To: <20230320223723.2030960-1-edliaw@google.com> Mime-Version: 1.0 References: <20230320223723.2030960-1-edliaw@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230320223723.2030960-4-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 v1 3/3] 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" On Android, the backing devices are created in /dev/block/ and will not be found using the method added in e1b1ae66b240 ("tst_find_backing_dev: Get dev name from /sys/dev/block/*/uevent"). Adds a check for /dev/block/%s as well as /dev/%s. Signed-off-by: Edward Liaw --- lib/tst_device.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/tst_device.c b/lib/tst_device.c index ae665f7b6..14c0dd7a3 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_size) { 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_size) != 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);