Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3261665rwb; Mon, 15 Aug 2022 22:37:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR7nq9EJyysLQrggE8aV6bUaWH8t7Q/GFK6riACsm6+oIRzNvhjMzSkwiMuaxNd0YgNtcK8S X-Received: by 2002:a17:907:7b95:b0:731:113a:d7a2 with SMTP id ne21-20020a1709077b9500b00731113ad7a2mr11831793ejc.377.1660628219905; Mon, 15 Aug 2022 22:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660628219; cv=none; d=google.com; s=arc-20160816; b=pf0Alm1hrdj3LKHnNqu6ytJbKnYGSBeN6wOk3MF9/GZwk8ztGdQr0WNjuoELm3jlg1 bnBlRYiKWYcxa5rZvyioArwOZvsJSEuwW5tuEK4CLQ9YOAN+hDHPX+hjHw96d+rz9ji+ V5Qw23cz1DWkDxFMxWjpcPSiaPpKbksDOpBEF428abUApM8zLqCz6k+Y1X9li+rlEsNo gvWldEYVa2NNfYKosNOF2zflkx9XGbpOE/lpHQMDQDjNL3jTR0i4+mnKMT2GN27J0Wwo n2o3nuTVWOCzhhoD6YNWXLc+6WLXaVjsyie9l+oiWfUEEfwprdtg0plz4ZBTjroTqgv+ czGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FPmQ7+KASqmRhZVSXfu+kgAWp5LQmPKz4FRQZJYRP9U=; b=U9cJ3ZXEKLWRuDvCZR6s0TMc77fChnePPXVGfOpTwrN1FpxhuL5SS2aXdwlyErCcpQ QQxccyRf+gs5TQAh55LjmFXOYpzYeE1sU2qPGdh2jGu4tl/CHJXH1toLQrlWAHyadsx0 ihpYNcOlwqWmvzilgGWyf0K6UKRX7aYLcwt8xXnooMm6VlXce3Odw+5klNWeOd3wjrBG 3aehNDxWZD6jF2ZCrE4ZH6u5VZArCy/ws7QGqeSYZ4mgAlulsn2MNiDbtghqdhdEHm39 gQG+BDx0SWgIosaqz9U/93y7mrpvSO67btMa2lfsuyeMmcJyS+l2u+vhSfIeZOom3cF3 7SNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=YCg2rMZM; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020a056402348f00b0043a10e5e81asi9576738edc.66.2022.08.15.22.36.34; Mon, 15 Aug 2022 22:36:59 -0700 (PDT) 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=fail header.i=@mit.edu header.s=outgoing header.b=YCg2rMZM; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231869AbiHPFBs (ORCPT + 99 others); Tue, 16 Aug 2022 01:01:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234628AbiHPFBP (ORCPT ); Tue, 16 Aug 2022 01:01:15 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C26B54F196 for ; Mon, 15 Aug 2022 13:56:33 -0700 (PDT) Received: from cwcc.thunk.org (pool-108-49-209-117.bstnma.fios.verizon.net [108.49.209.117]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 27FKuN1n000856 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 16:56:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1660596985; bh=FPmQ7+KASqmRhZVSXfu+kgAWp5LQmPKz4FRQZJYRP9U=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=YCg2rMZM8OAjOqcCHM30A9yp1J6T8xLGMwqL+r79/XwAxtVXVIiunK88zmATRMaM9 kANDI2xf306YWWqJ610nHD3pTdnEPyC/kXYZZXeCyq6i1TVT1ThHIHWhXMma6ML/xz zCqCA38ILMyPh8Z/ai1nQj/wlq926aMlFQ7oNxGRZdazqyI9Sfb+ruiiklicHf4uol xIpg5+4uYE2j8UPgx7PBRf5UZfvpHHt51U1/drWyHZW0yAJAOId3pYWbpLSrxxM7cp 0+krMGr8TS+auYSEIWDh2QBTfuTmeboG2s/mjdUp9z0rNXi7x0B7NPi98rFNz4nc3s RxKB6a9zc1SCw== Received: by cwcc.thunk.org (Postfix, from userid 15806) id 7EC6215C350A; Mon, 15 Aug 2022 16:56:23 -0400 (EDT) Date: Mon, 15 Aug 2022 16:56:23 -0400 From: "Theodore Ts'o" To: Jeremy Bongio Cc: linux-ext4@vger.kernel.org Subject: Re: [PATCH v3] tune2fs: Add support for get/set UUID ioctls. Message-ID: References: <20220719235204.237526-1-bongiojp@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220719235204.237526-1-bongiojp@gmail.com> X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, 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 On Tue, Jul 19, 2022 at 04:52:04PM -0700, Jeremy Bongio wrote: > +/* > + * Use EXT4_IOC_GETFSUUID/EXT4_IOC_SETFSUUID to get/set file system UUID. > + * Return: 0 on success > + * -1 when the old method should be used > + */ > +int handle_fsuuid(__u8 *uuid, bool get) > +{ > + errcode_t ret; > + int mnt_flags, fd; > + char label[FSLABEL_MAX]; > + int maxlen = FSLABEL_MAX - 1; > + char mntpt[PATH_MAX + 1]; > + struct fsuuid *fsuuid = NULL; > + > + fsuuid = malloc(sizeof(*fsuuid) + UUID_SIZE); > + if (!fsuuid) > + return -1; fsuuid is not getting freed in this function, so this will leak memory. ... > + if (get) > + ret = ioctl(fd, EXT4_IOC_GETFSUUID, fsuuid); > + else > + ret = ioctl(fd, EXT4_IOC_SETFSUUID, fsuuid); In the EXT4_IOC_GETFSUUID case, you need to copy fsuuid->fsu_uuid to uuid, so it is returned to the caller. > + ret = ext2fs_check_mount_point(device_name, &mnt_flags, > + mntpt, sizeof(mntpt)); > + if (ret || !(mnt_flags & EXT2_MF_MOUNTED) || > + (!get && (mnt_flags & EXT2_MF_READONLY)) || > + !mntpt[0]) > + return -1; handle_fsuuid() is getting called twice by tune2fs when handling the -U option, which means we're calling ext2fs_check_mount_point() twice. And around line 3364, tune2fs calls ext2fs_check_if_mounted() which fetches the mnt_flags but which doesn't get the mountpoint. So I wonder if wouldn't be better off changing tune2fs's main() to call ext2fs_check_mount_point() instead of ext2fs_check_if_mounted(), and we can just determine the mountpoint once. Then, instead of calling handle_fsuuid/[gs]et_mounted_fsuuid, in the handling of -U, we can do something like this: if (U_flag) { int fd = -1; struct fsuuid *fsuuid = NULL; ... if ((mnt_flags & EXT2_MF_MOUNTED) && !(mnt_flags & EXT2_MF_READONLY) && mntpt) { fd = open(mntpt, O_RDONLY); if (fd >= 0) { fsuuid = malloc(sizeof(*fsuuid) + UUID_SIZE); if (!fsuuid) { close(fd); fd = -1; } } } In other words, we can just inline all of handle_fsuuid, and the call to get_mounted_fsuuid() just becomes: if (fd >= 0) { fsuuid->fsu_len - UUID_SIZE; fsuuid->fsu_flags = 0; ret = ioctl(fd, EXT4_IOC_GETFSUUID, fsuuid); } ... and similarly for set_mounted_fsuuid(). Then at the end of tune2fs -U processing, we can do something like this: if (fd >= 0) close(fd); free(fsuuid); - Ted