Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp503323pxb; Mon, 7 Feb 2022 17:08:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGbDHV5erkruukJc5YUCgJkz9CqjjyPTPziiy7CtqQ5EQeZ+qcx5cmzmOriXiPnIpc6nK3 X-Received: by 2002:a05:6402:1681:: with SMTP id a1mr2067813edv.167.1644282515456; Mon, 07 Feb 2022 17:08:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644282515; cv=none; d=google.com; s=arc-20160816; b=iH67gFwwa8WavNfWXDrYL9vk6aoQOZHVK9XRh/+3PUgYtjxIijfxOnbIy02VWbQ8R7 +bTmYOzGRN1bKhLLKn3ZQG1XD/BARQ0ya1WtYE6hsNDSv30fVwVl34WYEwJbc3rOwHya g+1vFOIRcrvL5+nwbKLUnT+ysVYhFFYF3KCMyfvNq/3s+xnCd0G8+0KlBRMc3ZUmcyWT XmnWhSGqEHFwD0wsu5Hm64qhqBK0bac8lNlWrGV7UZzeyw7REBcMsvFvrF8BfSvUNca0 nKxylMRS2et1xtxlI+tXbEMwK6oBRVHX3Cf83qm/JZbgdnDFqHI4olBErvs5iYasgd/c iX7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HUbvMics5B2UfKQFTdcC5lg28+CnFFfrSXmDm03GbiM=; b=z+hTG4Q8lo55dbgO2F7RKx79GM82QdezqSKx1+PngUdN3wYqgTRho1/1LuGgSucbjJ m4pd+TI8pdDdNelGDZhM58XTQqonna1uBOpPIYfx/vRNv65Q7ZV+Illx1qIkphGJYu8z 7E+sj1dhtCPc3rXqDDMDY9nzoPgFEj5OyYbowA1ShtoSUG8T1I3hPtENpACL7jRxRfRl jmaGZstnjclx7yhT+/oVgO3n9Q4kJE3d2zExYuzkQUK4Hy3SGJ7OYcl7e4H39t2IpqTz sAIIRoZl5YRpDunyUzh0G8i38/jXyY1CU1/yidV9KTdR0SZoi+mmxZSN/btUA0ECqnA0 dUCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Oo3pNg6u; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne1si810281ejc.945.2022.02.07.17.08.12; Mon, 07 Feb 2022 17:08:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Oo3pNg6u; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232066AbiBGMu1 (ORCPT + 99 others); Mon, 7 Feb 2022 07:50:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392245AbiBGMI7 (ORCPT ); Mon, 7 Feb 2022 07:08:59 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2A1C03FED0; Mon, 7 Feb 2022 04:01:29 -0800 (PST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2175MVst005253; Mon, 7 Feb 2022 08:26:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=HUbvMics5B2UfKQFTdcC5lg28+CnFFfrSXmDm03GbiM=; b=Oo3pNg6uvaOBpuxAPFNzLmu63ifvP1HGKOvMJ15TeVytoToqmkApfMdeOk+n0UBuTKt5 aXIiLoaeVe56VPabYzT2Hb7CE4oXBzyIKdV+dSl/H4Bh9UDKPFwiQR/JEKsElLu+BqBq WEOMKgVcWi2xEcuvaCQ6yeZ800TxmXVw2YCF7qAfKGkJR4IPIUR40kK/O/sBziDqKpJE XA3Z70dtteHnaxljZlcyGfc0BA8dEQMYicdhqqIJiep+N8ElV4MsAWPhWMneJFtssYu8 Fd+7Q+zUpxmAIL4JP+jp1gnvkMHubj1yycJJK+PVDbOxhCmWDztGyKxXHj8kU0bgNjQz hw== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3e22ssp40y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Feb 2022 08:26:26 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2178Cawm005087; Mon, 7 Feb 2022 08:26:24 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 3e1gv91y6k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Feb 2022 08:26:24 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2178GI4v19988982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Feb 2022 08:16:19 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F05A9A4051; Mon, 7 Feb 2022 08:26:20 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A7942A4040; Mon, 7 Feb 2022 08:26:17 +0000 (GMT) Received: from li-bb2b2a4c-3307-11b2-a85c-8fa5c3a69313.ibm.com (unknown [9.43.26.84]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 7 Feb 2022 08:26:17 +0000 (GMT) From: Ojaswin Mujoo To: fstests@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Ojaswin Mujoo , riteshh@linux.ibm.com Subject: [PATCH 1/2] src/ext4_resize.c: Refactor code and ensure accurate errno is returned Date: Mon, 7 Feb 2022 13:55:33 +0530 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: LACZOXZF2WfgJQH54FOM5vbdhAgZ7BQw X-Proofpoint-ORIG-GUID: LACZOXZF2WfgJQH54FOM5vbdhAgZ7BQw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-07_03,2022-02-03_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 spamscore=0 suspectscore=0 malwarescore=0 mlxscore=0 mlxlogscore=981 impostorscore=0 bulkscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202070053 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The current implementation of ext4_resize returned 1 whenever there was an error. Modify this to return the correct error code. This is important for tests that rely on correct error reporting, by the kernel, for ext4 resize functionality. Additionaly, perform some code cleanup. Signed-off-by: Ojaswin Mujoo --- src/ext4_resize.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/ext4_resize.c b/src/ext4_resize.c index 39e16529..78b66432 100644 --- a/src/ext4_resize.c +++ b/src/ext4_resize.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -19,33 +20,50 @@ typedef unsigned long long __u64; #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64) #endif +#define pr_error(fmt, ...) do { \ + fprintf (stderr, "ext4_resize.c: " fmt, ##__VA_ARGS__); \ +} while (0) + +static void usage(void) +{ + fprintf(stdout, "\nUsage: ext4_resize [mnt_path] [new_size(blocks)]\n"); +} + int main(int argc, char **argv) { __u64 new_size; int error, fd; - char *tmp = NULL; + char *mnt_dir = NULL, *tmp = NULL; if (argc != 3) { - fputs("insufficient arguments\n", stderr); - return 1; - } - fd = open(argv[1], O_RDONLY); - if (!fd) { - perror(argv[1]); - return 1; + error = EINVAL; + pr_error("insufficient arguments\n"); + usage(); + return error; } + mnt_dir = argv[1]; + errno = 0; new_size = strtoull(argv[2], &tmp, 10); if ((errno) || (*tmp != '\0')) { - fprintf(stderr, "%s: invalid new size\n", argv[0]); - return 1; + error = errno; + pr_error("invalid new size\n"); + return error; + } + + fd = open(mnt_dir, O_RDONLY); + if (fd < 0) { + error = errno; + pr_error("open() failed with error: %s\n", strerror(error)); + return error; } - error = ioctl(fd, EXT4_IOC_RESIZE_FS, &new_size); - if (error < 0) { - perror("EXT4_IOC_RESIZE_FS"); - return 1; + if(ioctl(fd, EXT4_IOC_RESIZE_FS, &new_size) < 0) { + error = errno; + pr_error("EXT4_IOC_RESIZE_FS ioctl() failed with error: %s\n", strerror(error)); + return error; } + return 0; } -- 2.27.0