Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp212626pxb; Wed, 4 Nov 2020 20:09:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBd+lESAZhV/5e5Gix05eqkwsVq2jse3UvcMBBqsH+YemyN67/yiSJhjpHV12146qDN3sq X-Received: by 2002:a17:906:4e56:: with SMTP id g22mr449235ejw.49.1604549380856; Wed, 04 Nov 2020 20:09:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604549380; cv=none; d=google.com; s=arc-20160816; b=yqqP+lwmSuiDU0BXLvQVUlo1R0lbX1zRIsGFur2IOrBqIcKi9KsfjlFBR7AHBSkgAf +LnDb6Y9SOsmxiKZcDIghHnjZ3Dg/cuyFyx4bnCl1s4inW8YzGY/h5nvnheKwFHGvh10 MmcEQgmatIZnmJFLYJJngdBwOfqpQ0vy/zk34tJ/mrYRJJ//tfg5qaShoEEB9rkDviD8 FbOTEJuvL2NqegsSm4Sk5q+a3mr5v4tDxR0K2HOBT1Xp8CjUTY5ERs84EgMFCUk5Ufkk pQQMLrnRJ+Mbb1sYijU0gm+w3HZcZs4llgxuXdhElWI4jta3CRUUqWWcZ9R2+z5aD8lR GJYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=deYhQxEoIE1YLwyzlLXaTbIaoKfq7PUxqicRTlZpWTk=; b=0C1ACX4ATakGDDAdoz2AUWoNpc6kBfho7f9dJNcUf0mhtbSviRltiG5g3OfKeTT7A7 km/15p/WumoRb7n/6QaxHCaQlg+8zkqyPrbK/mFlRuXyJafDcFwkhp4sTXw7Dx+1Uezp MX0tjY3CoK15eO1Hvpz3oRDyIEcxsJKmY5TfBRt9MVXfIN+zL4WaL6Lmbo7xARxw6och /3HBT9xZ6tVSWCMz/6cwOpK1a1eMWTaYx9iUjMB7KtF9K6l2mjjma1J3dmJhNgSBb9dU OC38VWn+PXbQQ6+5xsAuKvCMnKc7T97bIEUbjq+oGWUr9+EqOG93lHfL1/k59D4I+Szw 9NuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si286786edr.585.2020.11.04.20.09.19; Wed, 04 Nov 2020 20:09:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387981AbgKEBBH (ORCPT + 99 others); Wed, 4 Nov 2020 20:01:07 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:7413 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728052AbgKEBBG (ORCPT ); Wed, 4 Nov 2020 20:01:06 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CRQF92qWxz71p3; Thu, 5 Nov 2020 09:01:01 +0800 (CST) Received: from [10.136.114.67] (10.136.114.67) by smtp.huawei.com (10.3.19.204) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 5 Nov 2020 09:00:59 +0800 Subject: Re: [f2fs-dev] [PATCH v2 2/2] f2fs: fix compat F2FS_IOC_{MOVE, GARBAGE_COLLECT}_RANGE To: Eric Biggers CC: , , References: <20201104064310.15769-1-yuchao0@huawei.com> <20201104064310.15769-2-yuchao0@huawei.com> <20201104180153.GB846@sol.localdomain> From: Chao Yu Message-ID: <2bec3d16-e920-12b9-562d-0e055c1af28e@huawei.com> Date: Thu, 5 Nov 2020 09:00:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20201104180153.GB846@sol.localdomain> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.136.114.67] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/11/5 2:01, Eric Biggers wrote: > On Wed, Nov 04, 2020 at 02:43:10PM +0800, Chao Yu wrote: >> +static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg) >> +{ >> + struct f2fs_gc_range range; >> + struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); >> + >> + if (!capable(CAP_SYS_ADMIN)) >> + return -EPERM; >> + if (f2fs_readonly(sbi->sb)) >> + return -EROFS; >> + if (copy_from_user(&range, (struct f2fs_gc_range __user *)arg, >> + sizeof(range))) >> + return -EFAULT; >> + >> + return __f2fs_ioc_gc_range(filp, &range); >> +} > [...] >> #ifdef CONFIG_COMPAT >> +static int f2fs_compat_ioc_gc_range(struct file *file, unsigned long arg) >> +{ >> + struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(file)); >> + struct compat_f2fs_gc_range __user *urange; >> + struct f2fs_gc_range range; >> + int err; >> + >> + if (unlikely(f2fs_cp_error(sbi))) >> + return -EIO; >> + if (!f2fs_is_checkpoint_ready(sbi)) >> + return -ENOSPC; >> + if (!capable(CAP_SYS_ADMIN)) >> + return -EPERM; >> + if (f2fs_readonly(sbi->sb)) >> + return -EROFS; >> + >> + urange = compat_ptr(arg); >> + err = get_user(range.sync, &urange->sync); >> + err |= get_user(range.start, &urange->start); >> + err |= get_user(range.len, &urange->len); >> + if (err) >> + return -EFAULT; >> + >> + return __f2fs_ioc_gc_range(file, &range); >> +} > > It would be better to have __f2fs_ioc_gc_range() handle the f2fs_cp_error(), > f2fs_is_checkpoint_ready(), capable(), and f2fs_readonly() checks, so that they > don't have to be duplicated in the native and compat cases. > > Similarly for "move range". Will clean up in v3. Thanks, > > - Eric > . >