Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp577675rwd; Mon, 12 Jun 2023 19:10:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5O03izOs07X250wOnpxWifD3v0YvPPz+pfS+qMaPjAP7danoU4pGx8EB9lASd7X+rPfKqg X-Received: by 2002:a05:6808:e87:b0:39a:522c:55c1 with SMTP id k7-20020a0568080e8700b0039a522c55c1mr5765892oil.8.1686622232904; Mon, 12 Jun 2023 19:10:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686622232; cv=pass; d=google.com; s=arc-20160816; b=BYT3krS6KbUUWG6dxgTYLoWOJTRvmZQAeEbX30z0w/wJRZa6+XSsbk4MhxssMfHz+S bPEqFINgLEMFZ40Riz6dt3vu4Xv169iiBsVY2f+3YcSL4JBYlhQ0YReTNqEF4vPgIWv0 qe/Z+wCHcArGRfMNJEF4pH8pFae0y9ID+qryjJKqszPJfixPb3J32POpv0mK69JRFi0X 9Mf5Dd2Kr7btVQLQCVPT+d2HEMESSJTNPi733CvKL0BAN90B6y2u4fgnbObejdxGomm1 x7ZY4LDIyIjraONJubAOrYLGPZQNKaJRsQmYiSGSB7zWBL/umbARMaqugdnjPzInOjnt 6jQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:content-language:references:cc:to:subject :user-agent:date:message-id:dkim-signature; bh=O7BevQuKPCIO62XN8BbzhJPp8Bgri1ZePNMMQ/Gtevw=; b=trLCvqRIRX+5t5SDmvxPzv2wkJ9jR/Iv1qSVELZpa2fMCEPHjWi1kcDR5ivhWq4nVu TVS1u+hgOOeeHycgWvCK/1+Z39v/qomRZ3N9Dx+LnqkKknkLfX17N3F652Rcy6xzWuT3 SaGTvlsZGd6/r4JD+2jx2ZIP7lybF97Lo4zemSp74umwX29nQ/GGIONaxs4JbAD0idmk kp3UpwBRX5V7YKqSnMRJyO75PnZdkPB3FVUSHNqUS51phTATpmCFFe7Y6iVYrwI2yOEA K/kQcKvE7O6N/xSr48ju9BP0G5WQa42l61FoclgBsLQvV7pFPMHXJ0v4iKBqTMl+6UtM QpsA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oppo.com header.s=selector1 header.b=KVVX36Ez; arc=pass (i=1 spf=pass spfdomain=oppo.com dkim=pass dkdomain=oppo.com dmarc=pass fromdomain=oppo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oppo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a17090aea8800b0025bcd532417si3466217pjz.25.2023.06.12.19.10.20; Mon, 12 Jun 2023 19:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@oppo.com header.s=selector1 header.b=KVVX36Ez; arc=pass (i=1 spf=pass spfdomain=oppo.com dkim=pass dkdomain=oppo.com dmarc=pass fromdomain=oppo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oppo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238864AbjFMByA (ORCPT + 99 others); Mon, 12 Jun 2023 21:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238836AbjFMBxw (ORCPT ); Mon, 12 Jun 2023 21:53:52 -0400 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2076.outbound.protection.outlook.com [40.107.215.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1347199C for ; Mon, 12 Jun 2023 18:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lw8Ike6KRW2jsB+uEi6RoqG70n2TrC7euEcIW/oSzuq9f0ienib7uXjtIpLXhsv6SPjZAAqviOTP2EdWtAVEii9o2eQQSfw+RPWR0XRXsaWThOfhSVOZkD0t8rO0zTphz3zVq8E2DXiHBFRKkiSEGXhLyiUGyK54tkrIbTTnndUNMm0zdfz/uqWvEt6n7yo2AH9TvfbM4inxxLWq28pdODb7NamjwsjQVg0DBTheyy6f+MUsjTHkOm7Sd8YsrDMLf8+FOaaJ0mN0xa9yjTuFIHyhZ+u8QMsmmHov3JTDOBIiMEzN/NeDd4Ia4RUPsrNDLELi2rIobuImYOiZEdzZOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O7BevQuKPCIO62XN8BbzhJPp8Bgri1ZePNMMQ/Gtevw=; b=XFWi4QuPzpsgbN9pPrSGoXoUTHzmpkbWIDIZGI+Hncyal/kbdjUWiflGynzYpp/B7w1bPVg2/BpHzlEWOHSysE+M6NeK5L4gfIDRv7rf8CjA1KZfs/ulzsx+TjJntl7ouhXpAxLVaonZwludmybKGvkWQBjKG7KytpFhlmHyJ8liB8XMCJGqBkZZiiYzflT1Jt+kyKFmHoafFZYxHJOYs8q7HZ3I1gCF95zO93vOxo395JkBEymRSCNy2QaEkmDQFh+bnQAPOqUdtZrWhQxkTZ7WbIk7BnGVhS8KdZk/XDH4U605+3VR4Ou3J8UvjIP4fXlNP/lqgEN0LPk0Idj/1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O7BevQuKPCIO62XN8BbzhJPp8Bgri1ZePNMMQ/Gtevw=; b=KVVX36EzK+iELX5Fr7o+yxEC4ULhvss57NhjDYra55CIMCVjxS4rWVrFuetV1FRODdvv7bpURr+N0pqUTQoO8c+k084evuNoJ5isK+fmUKRlpVc1mR7EA9LkLPw6I1MLyPdPFqabmdbPOKQ+2fvQRRJhqWn4Pobb7Zxv3Zob9zQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SI2PR02MB5148.apcprd02.prod.outlook.com (2603:1096:4:153::6) by SEZPR02MB6133.apcprd02.prod.outlook.com (2603:1096:101:a0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.21; Tue, 13 Jun 2023 01:53:10 +0000 Received: from SI2PR02MB5148.apcprd02.prod.outlook.com ([fe80::6297:13a6:41f1:e471]) by SI2PR02MB5148.apcprd02.prod.outlook.com ([fe80::6297:13a6:41f1:e471%6]) with mapi id 15.20.6500.020; Tue, 13 Jun 2023 01:53:10 +0000 Message-ID: <66107ad2-1c1e-7e25-a8f5-167f4d06525c@oppo.com> Date: Tue, 13 Jun 2023 09:53:06 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH v4 5/6] f2fs: add f2fs_ioc_[get|set]_extra_attr To: Jaegeuk Kim Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, ebiggers@kernel.org References: <20230612030121.2393541-1-shengyong@oppo.com> <20230612030121.2393541-6-shengyong@oppo.com> Content-Language: en-US From: Sheng Yong In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SI2P153CA0031.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::7) To SI2PR02MB5148.apcprd02.prod.outlook.com (2603:1096:4:153::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SI2PR02MB5148:EE_|SEZPR02MB6133:EE_ X-MS-Office365-Filtering-Correlation-Id: 7388813c-4022-42b7-3f36-08db6bb0f0e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nzJxJDUlStB+hQCgYEYueeeto5BtD7pXvmnIInKrCgV15brQWPTCvZSlJg+4Pu/bLl9aLWbomAmE5FhFtREcTBfQVC//m8F5sd7x4y+G9m1cHjM8sS97HsAqeM62HCQrIlfOUdH3YX9EthZegqXZmfIcvZGcI0Hr7d7q0A4+8ZTSX6THsi5gQZkr/YpWjmv7bhLA2m3d4251i7a10vZOS6xPp6U+lllNj8R1wPWz+tcjXPMvcs1wiD2Qvbf4BR/JZOTtAerhwb5bVwVfUf4++PDnbdvTlqIQk695FM5U2HzUKRFDXZFxC4Hv3BIaCCu6KIF1sNfk1YbQMnhrI++mvMwbtoFtL25nieiv3xjhCFbSJ8rmfiBG5V1hnngwxSvgp62goJqXQI6FlOVKTHt1utl5wxZp/U8weoUrYI7PvIhEn45KCBLxHIeOwlePBH+nRh/WDZi7s6I35LJoJ/wGB+N4lhXv7fFbZumymwN7V/20ulq7R/AjiX3LQgqTUc49biAnlxTqz9yO8TSU5iVViXN8qDNmiXKlp9J8vfifhPtizlCH3IOmVv7cICyfAEOXsejK2HdDvBDydfEfJeWzoA5+0IZAXAb0gppJSo7vcb58sZOiegOm2CqFTXJfOdZwYR8FLl9eDLG4690fkjgZmQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SI2PR02MB5148.apcprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199021)(2616005)(83380400001)(38100700002)(86362001)(31696002)(36756003)(478600001)(4326008)(6666004)(966005)(6486002)(8936002)(8676002)(30864003)(2906002)(5660300002)(66556008)(66946007)(66476007)(31686004)(41300700001)(6916009)(316002)(53546011)(186003)(6512007)(6506007)(26005)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YVFvRFhoV1ZpKzV0S2ZiU24vUzlxQXlDRjhKL0lNQ3cvUzRISjRhU0orcXZy?= =?utf-8?B?ZkFPQkhLRnBCNEpmbE9aZmJvNG5HckFQQTBIQUVkL0l4b0R6dXpFVjU1UmVC?= =?utf-8?B?cjMyampOeVM1anFIR243ZEU1TStjWE5Od1MyRHlES0VYVlU4K2JENFF1V0F5?= =?utf-8?B?cnBtbkg4QjhUalFhWm5PbXlocU0rTWhXZDg3ajEreTNGNk1iS3ZibFBlVGNW?= =?utf-8?B?K1U2NDNrSVF6UmxxUWgrSnJMVFBzWUcyM1I2dlZLZDJqR3pmTXpMZGNNUVlG?= =?utf-8?B?OVFickNzWk15bHJicStqTDJ2U0tiVE95L29xbmZJdUhzdjhYWjJlVEQxR2J0?= =?utf-8?B?UjRIKzhHSWkrbTFmS2xVYllweUNjYWxONzg0L1dSMlFVY2FOQkJSV3JlQjZH?= =?utf-8?B?Wk0vai9WTTR0Q25JVXdIV3hmUUdsWEtpcVl4UE9seEpQblRSckpZdGRUaGRC?= =?utf-8?B?VkdhMVJNOC9KL3VXR255VVN5b09tOE9NZTdIOEpFYkJ2UVN2Q051ZFNWclpM?= =?utf-8?B?dzVUaW5VRVpUcWtVNDBDOGIrSXE0bWZwMVlERGhRTnhHYWt3ZlBXN2Evb1Js?= =?utf-8?B?dzlUVGJGYVpsdFNBSDQrMDFUYWkwcHorbVE4WkY5dWNQNkZGY1B4a1FRVk1Z?= =?utf-8?B?bXFzTUF3WXhUL2c4WG9xdWk2a2M5SVUrRElIbU1laENsb1JZV1AyYm1ZY1ZB?= =?utf-8?B?UVdMTXZDZmcwak0vYVZKZ0dnZmw0cGFwQ01lU0NEdFZ6TDRnZlpVdVA3aWds?= =?utf-8?B?YndGZFp5dzl2L2svcXRRc1pZVE4rcUJOR1p4d1dsU2xwY2pvaWxVQU5icVAx?= =?utf-8?B?dkxSem5sMzMydWRBMjBFVmhXZFpKN3lPeDdHVmVMczk5YlgvSDFjNjhZZ2Zm?= =?utf-8?B?VzBtdFhUWVAxeHkyTUxocFBGTW1Xc2hQRHJVVzN0elVxYWV4b1JiS1BDeUJT?= =?utf-8?B?c2YvYm1raUMzOHNiZWhWcHpzVUtIcUE1ZHRzOHBsenQ5Vno2dUttOHZYVDVX?= =?utf-8?B?OUk3KzA1QVMzeEFXY01Qbm1wa0p4MXU1NUFUTzRhZzFhTERUYkhxb25IZE92?= =?utf-8?B?ajViNEo1SlMvQ2V2OVF4VVNuTTAzcHdVRmZGRlFpSCtrMllqNlpTaGU4RE1W?= =?utf-8?B?d0RaQVpHVVlhQkFaU1JramIzZG02VXJSQ0NzQ0dtQ3AvRWFWL1dCdGU2UHFa?= =?utf-8?B?cHdKYzMyQ3drU1E1ZW92NWxvRkFwZ1VhSFA1SUI0WEg0djhyNHRCcSs5N2JQ?= =?utf-8?B?NVhUbmorQ0swTmNJWklwYStYQ3dWRXphYmxoaDJIdSsvaGRrWEhUcjM1SXBp?= =?utf-8?B?ZG9rY29VbGgxODJRWVFsY0NNRklqTS92dVNJMENUOGJyc1Y4bjJjekNMeGFy?= =?utf-8?B?aW9lK0tjZGg4L2ZaYWIzK3RLQXJ5czhJdVV0UmtOT1Q3bVNobmt3WFVHYUI0?= =?utf-8?B?WGNQNDBQQ0RxUHE5WUFXRnBRVkNtRktPQTBiQkluK2x4Zm1UYkVpb1lQNzRQ?= =?utf-8?B?WE9sNmJaOVo4SUNXRytZZlRiNWZVemxaekFGd0x1dFYyampwaXArV2hETzVO?= =?utf-8?B?ZTllZ2lFMmMwSXBiVFVENWVxS3R1d1JZQXFTc0tJTmZZMExkK3dwcUU1bHly?= =?utf-8?B?djkrdDh6Nmp4N0NIQWkzcWpUVEx3QXk0ZVRvTlJ5N2I0ejFiUUxyNXVDRHN4?= =?utf-8?B?OFdFUFJnTHBzMXhxYk1leUROS2Z4OTZWUkpFbjd4aUtSaE85bHZvK1QrNHhm?= =?utf-8?B?aklOZUF4Vk1RcnhVekNPcTZHV284dTVGUlduUUtnbXhtbkhTZnNOSWsrMDNo?= =?utf-8?B?RnBnNWlFRkthQ3ZTODRYU0ZKVy9QeTFUdzN5cFJQWXFnTXA0bm4zaGlzSnNL?= =?utf-8?B?bXN0NXBWUkl4YUJvVW5TT0k5aWc5QlQ0WDJtRXI2TUxxYUJ1VytnblkyZUpu?= =?utf-8?B?NmdvWnM3VnhSNFNHWFhVWEhVU3VNOFNPSWg4bkpxUTZDci9nZVQ4SEVtdjlo?= =?utf-8?B?Y0o3cGg0UGl1SWtONnJQeTFoaXJ0cjRiYjEyUXRUak9COVZqWGZpOGhyYnAx?= =?utf-8?B?WFQxczRjTEh1NDFVNFBKMFhQVUtSaGczdUxzNHVPR0tqcHpOemhqTFpJRnZl?= =?utf-8?Q?I1a/t1RNB+09sibVO8Z7r2TRK?= X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7388813c-4022-42b7-3f36-08db6bb0f0e2 X-MS-Exchange-CrossTenant-AuthSource: SI2PR02MB5148.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2023 01:53:10.3669 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ztNKmPQlS0yKSYTddmhH1XUiha6jIy64gG3k82MxYzM2tMI4Mcw03niR1VAmYP7OSo64jHPJLrnjjLZaH24JeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB6133 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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-kernel@vger.kernel.org On 2023/6/12 23:47, Jaegeuk Kim wrote: > On 06/12, Sheng Yong wrote: >> This patch introduces two ioctls: >> * f2fs_ioc_get_extra_attr >> * f2fs_ioc_set_extra_attr >> to get or modify values in f2fs_inode's extra attribute area. > > What'd be the main purpose of this new ioctl? Use-cases or examples? Hi, Jaegeuk, When a new feature is added, f2fs_inode extra attributes needs to be extended sometimes to save status or control values, say compression, inode chksum, inode crtime. If some of them could be read or modified during runtime, a new ioctl is required in most cases, like F2FS_IOC_GET_COMPRESS_BLOCKS, F2FS_IOC_GET_COMPRESS_OPTION... And Yangtao [1] and I [2] also tried to add new ioctls to allow getting and settingcompress level and flags. If new features are added in the future, we may get a verty long and not-easy-to-extend ioctl list. So these 2 ioctls could help manage all extra attributes: * if a new extra attribute is added, we only need to add a new field type, and corresponding get/set functions * attr_size can indicate which version of attribute is used * besides, ioc_set_extra_attr(i_inline_xattr_size) gives us a chance to adjust inline xattr size for an empty file thanks, shengyong Links: [1] https://lore.kernel.org/linux-f2fs-devel/20230112133503.16802-1-frank.li@vivo.com/ [2] https://sourceforge.net/p/linux-f2fs/mailman/linux-f2fs-devel/?viewmonth=202303 > >> >> The argument of these two ioctls is `struct f2fs_extra_attr', which has >> three members: >> * field: indicates which field in extra attribute area is handled >> * attr: value or userspace pointer >> * attr_size: size of `attr' >> >> The `field' member could help extend functionality of these two ioctls >> without modify or add new interfaces, if more fields are added into >> extra attributes ares in the feture. >> >> Signed-off-by: Sheng Yong >> --- >> fs/f2fs/file.c | 205 ++++++++++++++++++++++++++++++++++++++ >> include/uapi/linux/f2fs.h | 25 +++++ >> 2 files changed, 230 insertions(+) >> >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >> index f8aa842b5d233..39d04f8f0bb6b 100644 >> --- a/fs/f2fs/file.c >> +++ b/fs/f2fs/file.c >> @@ -4179,6 +4179,207 @@ static int f2fs_ioc_compress_file(struct file *filp) >> return ret; >> } >> >> +static bool extra_attr_fits_in_inode(struct inode *inode, int field) >> +{ >> + struct f2fs_inode_info *fi = F2FS_I(inode); >> + struct f2fs_inode *ri; >> + >> + switch (field) { >> + case F2FS_EXTRA_ATTR_TOTAL_SIZE: >> + case F2FS_EXTRA_ATTR_ISIZE: >> + case F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE: >> + return true; >> + case F2FS_EXTRA_ATTR_PROJID: >> + if (!F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_projid)) >> + return false; >> + return true; >> + case F2FS_EXTRA_ATTR_INODE_CHKSUM: >> + if (!F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_inode_checksum)) >> + return false; >> + return true; >> + case F2FS_EXTRA_ATTR_CRTIME: >> + if (!F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_crtime)) >> + return false; >> + return true; >> + case F2FS_EXTRA_ATTR_COMPR_BLOCKS: >> + case F2FS_EXTRA_ATTR_COMPR_OPTION: >> + if (!F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_compr_blocks)) >> + return false; >> + return true; >> + default: >> + BUG_ON(1); >> + return false; >> + } >> +} >> + >> +static int f2fs_ioc_get_extra_attr(struct file *filp, unsigned long arg) >> +{ >> + struct inode *inode = file_inode(filp); >> + struct f2fs_inode_info *fi = F2FS_I(inode); >> + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); >> + struct f2fs_extra_attr attr; >> + u32 chksum; >> + int ret = 0; >> + >> + if (!f2fs_has_extra_attr(inode)) >> + return -EOPNOTSUPP; >> + >> + if (copy_from_user(&attr, (void __user *)arg, sizeof(attr))) >> + return -EFAULT; >> + >> + if (attr.field >= F2FS_EXTRA_ATTR_MAX) >> + return -EINVAL; >> + >> + if (!extra_attr_fits_in_inode(inode, attr.field)) >> + return -EOPNOTSUPP; >> + >> + switch (attr.field) { >> + case F2FS_EXTRA_ATTR_TOTAL_SIZE: >> + attr.attr = F2FS_TOTAL_EXTRA_ATTR_SIZE; >> + break; >> + case F2FS_EXTRA_ATTR_ISIZE: >> + attr.attr = fi->i_extra_isize; >> + break; >> + case F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE: >> + if (!f2fs_has_inline_xattr(inode)) >> + return -EOPNOTSUPP; >> + attr.attr = get_inline_xattr_addrs(inode); >> + break; >> + case F2FS_EXTRA_ATTR_PROJID: >> + if (!f2fs_sb_has_project_quota(F2FS_I_SB(inode))) >> + return -EOPNOTSUPP; >> + attr.attr = from_kprojid(&init_user_ns, fi->i_projid); >> + break; >> + case F2FS_EXTRA_ATTR_INODE_CHKSUM: >> + ret = f2fs_inode_chksum_get(sbi, inode, &chksum); >> + if (ret) >> + return ret; >> + attr.attr = chksum; >> + break; >> + case F2FS_EXTRA_ATTR_CRTIME: >> + if (!f2fs_sb_has_inode_crtime(sbi)) >> + return -EOPNOTSUPP; >> + if (attr.attr_size == sizeof(struct timespec64)) { >> + if (put_timespec64(&fi->i_crtime, >> + (void __user *)(uintptr_t)attr.attr)) >> + return -EFAULT; >> + } else if (attr.attr_size == sizeof(struct old_timespec32)) { >> + if (put_old_timespec32(&fi->i_crtime, >> + (void __user *)(uintptr_t)attr.attr)) >> + return -EFAULT; >> + } else { >> + return -EINVAL; >> + } >> + break; >> + case F2FS_EXTRA_ATTR_COMPR_BLOCKS: >> + if (attr.attr_size != sizeof(__u64)) >> + return -EINVAL; >> + ret = f2fs_get_compress_blocks(inode, &attr.attr); >> + break; >> + case F2FS_EXTRA_ATTR_COMPR_OPTION: >> + ret = f2fs_ioc_get_compress_option(filp, attr.attr); >> + break; >> + default: >> + return -EINVAL; >> + } >> + >> + if (ret < 0) >> + return ret; >> + >> + if (copy_to_user((void __user *)arg, &attr, sizeof(attr))) >> + return -EFAULT; >> + >> + return 0; >> +} >> + >> +static int f2fs_ioc_set_extra_attr(struct file *filp, unsigned long arg) >> +{ >> + struct inode *inode = file_inode(filp); >> + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); >> + struct f2fs_extra_attr attr; >> + struct page *ipage; >> + void *inline_addr; >> + int ret; >> + >> + if (!f2fs_has_extra_attr(inode)) >> + return -EOPNOTSUPP; >> + >> + if (copy_from_user(&attr, (void __user *)arg, sizeof(attr))) >> + return -EFAULT; >> + >> + if (attr.field >= F2FS_EXTRA_ATTR_MAX) >> + return -EINVAL; >> + >> + if (!extra_attr_fits_in_inode(inode, attr.field)) >> + return -EOPNOTSUPP; >> + >> + switch (attr.field) { >> + case F2FS_EXTRA_ATTR_TOTAL_SIZE: >> + case F2FS_EXTRA_ATTR_ISIZE: >> + case F2FS_EXTRA_ATTR_PROJID: >> + case F2FS_EXTRA_ATTR_INODE_CHKSUM: >> + case F2FS_EXTRA_ATTR_CRTIME: >> + case F2FS_EXTRA_ATTR_COMPR_BLOCKS: >> + /* read only attribtues */ >> + return -EOPNOTSUPP; >> + case F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE: >> + if (!f2fs_sb_has_flexible_inline_xattr(sbi) || >> + !f2fs_has_inline_xattr(inode)) >> + return -EOPNOTSUPP; >> + if (attr.attr < MIN_INLINE_XATTR_SIZE || >> + attr.attr > MAX_INLINE_XATTR_SIZE) >> + return -EINVAL; >> + inode_lock(inode); >> + f2fs_lock_op(sbi); >> + f2fs_down_write(&F2FS_I(inode)->i_xattr_sem); >> + if (i_size_read(inode) || F2FS_I(inode)->i_xattr_nid) { >> + /* >> + * it is not allowed to set this field if the inode >> + * has data or xattr node >> + */ >> + ret = -EFBIG; >> + goto xattr_out_unlock; >> + } >> + ipage = f2fs_get_node_page(sbi, inode->i_ino); >> + if (IS_ERR(ipage)) { >> + ret = PTR_ERR(ipage); >> + goto xattr_out_unlock; >> + } >> + inline_addr = inline_xattr_addr(inode, ipage); >> + if (!IS_XATTR_LAST_ENTRY(XATTR_FIRST_ENTRY(inline_addr))) { >> + ret = -EFBIG; >> + } else { >> + struct f2fs_xattr_header *hdr; >> + struct f2fs_xattr_entry *ent; >> + >> + F2FS_I(inode)->i_inline_xattr_size = (int)attr.attr; >> + inline_addr = inline_xattr_addr(inode, ipage); >> + hdr = XATTR_HDR(inline_addr); >> + ent = XATTR_FIRST_ENTRY(inline_addr); >> + hdr->h_magic = cpu_to_le32(F2FS_XATTR_MAGIC); >> + hdr->h_refcount = cpu_to_le32(1); >> + memset(ent, 0, attr.attr - sizeof(*hdr)); >> + set_page_dirty(ipage); >> + ret = 0; >> + } >> + f2fs_put_page(ipage, 1); >> +xattr_out_unlock: >> + f2fs_up_write(&F2FS_I(inode)->i_xattr_sem); >> + f2fs_unlock_op(sbi); >> + inode_unlock(inode); >> + if (!ret) >> + f2fs_balance_fs(sbi, true); >> + break; >> + case F2FS_EXTRA_ATTR_COMPR_OPTION: >> + ret = f2fs_ioc_set_compress_option(filp, attr.attr); >> + break; >> + default: >> + return -EINVAL; >> + } >> + >> + return ret; >> +} >> + >> static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) >> { >> switch (cmd) { >> @@ -4265,6 +4466,10 @@ static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) >> return f2fs_ioc_decompress_file(filp); >> case F2FS_IOC_COMPRESS_FILE: >> return f2fs_ioc_compress_file(filp); >> + case F2FS_IOC_GET_EXTRA_ATTR: >> + return f2fs_ioc_get_extra_attr(filp, arg); >> + case F2FS_IOC_SET_EXTRA_ATTR: >> + return f2fs_ioc_set_extra_attr(filp, arg); >> default: >> return -ENOTTY; >> } >> diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h >> index 955d440be1046..2b53e90421bfc 100644 >> --- a/include/uapi/linux/f2fs.h >> +++ b/include/uapi/linux/f2fs.h >> @@ -43,6 +43,10 @@ >> #define F2FS_IOC_DECOMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 23) >> #define F2FS_IOC_COMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 24) >> #define F2FS_IOC_START_ATOMIC_REPLACE _IO(F2FS_IOCTL_MAGIC, 25) >> +#define F2FS_IOC_GET_EXTRA_ATTR _IOR(F2FS_IOCTL_MAGIC, 26, \ >> + struct f2fs_extra_attr) >> +#define F2FS_IOC_SET_EXTRA_ATTR _IOW(F2FS_IOCTL_MAGIC, 27, \ >> + struct f2fs_extra_attr) >> >> /* >> * should be same as XFS_IOC_GOINGDOWN. >> @@ -96,4 +100,25 @@ struct f2fs_comp_option { >> __u8 log_cluster_size; >> }; >> >> +enum { >> + F2FS_EXTRA_ATTR_TOTAL_SIZE, /* ro, size of extra attr area */ >> + F2FS_EXTRA_ATTR_ISIZE, /* ro, i_extra_isize */ >> + F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE, /* rw, i_inline_xattr_size */ >> + F2FS_EXTRA_ATTR_PROJID, /* ro, i_projid */ >> + F2FS_EXTRA_ATTR_INODE_CHKSUM, /* ro, i_inode_chksum */ >> + F2FS_EXTRA_ATTR_CRTIME, /* ro, i_crtime, i_crtime_nsec */ >> + F2FS_EXTRA_ATTR_COMPR_BLOCKS, /* ro, i_compr_blocks */ >> + F2FS_EXTRA_ATTR_COMPR_OPTION, /* rw, i_compress_algorithm, >> + * i_log_cluster_size >> + */ >> + F2FS_EXTRA_ATTR_MAX, >> +}; >> + >> +struct f2fs_extra_attr { >> + __u8 field; /* F2FS_EXTRA_ATTR_* */ >> + __u8 rsvd1; >> + __u16 attr_size; /* size of @attr */ >> + __u32 rsvd2; >> + __u64 attr; /* attr value or pointer */ >> +}; >> #endif /* _UAPI_LINUX_F2FS_H */ >> -- >> 2.40.1