From patchwork Mon May 20 16:46:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13668478 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDEFE7C6C6 for ; Mon, 20 May 2024 16:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223606; cv=none; b=ZvkzhI2Y4eth1RgE76HClQZLN05EwAJy48RcTumTM7chuxpyeEkz4icZNVrW0cieTCuk0lrsLzn7YY1TwGtKTGhTVeF/283SkDV3aLqH5RlD4sKSPrdZ4WD6125Ntm8jRku6o2sGemDmEPgLVQcu/dmq7Yxh5UvK4OEpCUIn9gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223606; c=relaxed/simple; bh=ugfIve/MBoJ8lNXTtpo8ReL0nr2qmk5vFiPzMIYkrC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BcnzLs3GJgDAwTt/Tc7z6cn/sl0fvSOV8bmTulqjRyuv4c9vE3W4JAElUc4bqBeq+J2vO8S53gtuFMMKJgduqicmkz6/Wv+AadEgMLWsa9NLvg7fZRFhuGuWsN0DF5zSyMUhrCI/5xPAZo5UN0TItxOH68pZK+QuPj7MzAFPi8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JRDvbVFm; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JRDvbVFm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716223603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=30mOQiH4aadYmFiJ3Era8Nm22mVGbDn077f7QuA+8e4=; b=JRDvbVFmZDKUIviWuiPH2nzsf3WmhHitnFp/sZNDaBruk9MP+5R2KDZ8p+cTZ+OSi7FlV8 iQCfcA3Fu3IF5ZRsOJspLMoVFvU2jP/iOc6+X/Gwk0gnG8FQoqr54ZO30k+/cjhIrbcRDJ 7Yy91STpsnsJcJq6f7cxORVCnWzxAjs= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-146-Pp012shrNFiRD9OrDXOojg-1; Mon, 20 May 2024 12:46:42 -0400 X-MC-Unique: Pp012shrNFiRD9OrDXOojg-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5732229087bso4172237a12.0 for ; Mon, 20 May 2024 09:46:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716223601; x=1716828401; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=30mOQiH4aadYmFiJ3Era8Nm22mVGbDn077f7QuA+8e4=; b=TynHWAYWgNc+63KHFO5yov3BVdMBZxokx7k1/J5Ps/AGJ8I0tBeqJkYuJcHCWcRWrG o/a9Tm8Udj6nPVYmoSanM+hAnNiZ4ItoRQxOkj52hIoiS07kiYeMTqdQBcNES1/RXc5g 5hu+ah04HB4iTD6SqHckgjEy0osO9AXqSnwdlfzpoIN3FEAEYr5nuCEDcU6KV94rpSv0 nJtBGawVKkH4s3FESVDRmxfP/l7KzIoZ2cAC8AcoGGpo71bnREf6n+eBjUGYLi6DTefI Fu+Dd6xmMeGHhrOhwtBYckJ3aIAOkJ4d+qlDMCHhB+nfJkGc6hbUIREVF39T5Q2PXpSG vuqg== X-Forwarded-Encrypted: i=1; AJvYcCU3iivkMejxWWpxs0gJRcNBdrdQ791Yk5gipzbdgvoVC3LmAutMHnxFWFRwtZ6sUj8GlUnGafo8+tiPAEjGwLTvi6cclrbe8wnI X-Gm-Message-State: AOJu0YwnAGB4flY0DayJzNutH76wCkv8jlriP+65VCXLqcp+Moi2/2c0 OyEzJAzu1ru6coXqteUm5Fw1da8JDKKi078PVvkgf9rn/njIRljt+h4UXXAukzqHT9J7bH7hlmR ml12bjaJ9iySH7Z6AlYZgDBM008fnI8c1HPsVdM4yr0PQQONV4OLbqiTn X-Received: by 2002:a17:906:528b:b0:a59:cf0a:4e4d with SMTP id a640c23a62f3a-a5a2d55a730mr1978883566b.12.1716223600817; Mon, 20 May 2024 09:46:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzQqgrZX3g47bHdERLya0zMK+/mL6vVJ64It+2IF6hpe95OUqWP3EskbV2iavRJuetYubLpA== X-Received: by 2002:a17:906:528b:b0:a59:cf0a:4e4d with SMTP id a640c23a62f3a-a5a2d55a730mr1978882066b.12.1716223600208; Mon, 20 May 2024 09:46:40 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5df00490cfsm318872066b.159.2024.05.20.09.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 09:46:39 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn , Chandan Babu R , "Darrick J. Wong" Subject: [PATCH v2 1/4] xfs: allow renames of project-less inodes Date: Mon, 20 May 2024 18:46:20 +0200 Message-ID: <20240520164624.665269-3-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240520164624.665269-2-aalbersh@redhat.com> References: <20240520164624.665269-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Identical problem as worked around in commit e23d7e82b707 ("xfs: allow cross-linking special files without project quota") exists with renames. Renaming special file without project ID is not possible inside PROJINHERIT directory. Special files inodes can not have project ID set from userspace and are skipped during initial project setup. Those inodes are left project-less in the project directory. New inodes created after project initialization do have an ID. Creating hard links or renaming those project-less inodes then fails on different ID check. Add workaround to allow renames of special files without project ID. Also, move it into the helper. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_inode.c | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 58fb7a5062e1..63f8814a3d16 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1297,6 +1297,35 @@ xfs_create_tmpfile( return error; } +static inline int +xfs_projid_differ( + struct xfs_inode *tdp, + struct xfs_inode *sip) +{ + /* + * If we are using project inheritance, we only allow hard link/renames + * creation in our tree when the project IDs are the same; else + * the tree quota mechanism could be circumvented. + */ + if (unlikely((tdp->i_diflags & XFS_DIFLAG_PROJINHERIT) && + tdp->i_projid != sip->i_projid)) { + /* + * Project quota setup skips special files which can + * leave inodes in a PROJINHERIT directory without a + * project ID set. We need to allow links to be made + * to these "project-less" inodes because userspace + * expects them to succeed after project ID setup, + * but everything else should be rejected. + */ + if (!special_file(VFS_I(sip)->i_mode) || + sip->i_projid != 0) { + return -EXDEV; + } + } + + return 0; +} + int xfs_link( struct xfs_inode *tdp, @@ -1346,27 +1375,9 @@ xfs_link( goto error_return; } - /* - * If we are using project inheritance, we only allow hard link - * creation in our tree when the project IDs are the same; else - * the tree quota mechanism could be circumvented. - */ - if (unlikely((tdp->i_diflags & XFS_DIFLAG_PROJINHERIT) && - tdp->i_projid != sip->i_projid)) { - /* - * Project quota setup skips special files which can - * leave inodes in a PROJINHERIT directory without a - * project ID set. We need to allow links to be made - * to these "project-less" inodes because userspace - * expects them to succeed after project ID setup, - * but everything else should be rejected. - */ - if (!special_file(VFS_I(sip)->i_mode) || - sip->i_projid != 0) { - error = -EXDEV; - goto error_return; - } - } + error = xfs_projid_differ(tdp, sip); + if (error) + goto error_return; if (!resblks) { error = xfs_dir_canenter(tp, tdp, target_name); @@ -3268,16 +3279,9 @@ xfs_rename( if (wip) xfs_trans_ijoin(tp, wip, 0); - /* - * If we are using project inheritance, we only allow renames - * into our tree when the project IDs are the same; else the - * tree quota mechanism would be circumvented. - */ - if (unlikely((target_dp->i_diflags & XFS_DIFLAG_PROJINHERIT) && - target_dp->i_projid != src_ip->i_projid)) { - error = -EXDEV; + error = xfs_projid_differ(target_dp, src_ip); + if (error) goto out_trans_cancel; - } /* RENAME_EXCHANGE is unique from here on. */ if (flags & RENAME_EXCHANGE) { From patchwork Mon May 20 16:46:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13668479 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47DBFE552 for ; Mon, 20 May 2024 16:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223607; cv=none; b=uv5aShAQ4RbF+/a2GFHD6aOSDAqTwlxcmRLjGD9bTUYfoc21N+TIpQnyfSNYlyMQmcNjDT75paPhexlMf0OXa5om+uxgQjnXagUyOozNg5ITOxddEOOwOUmlF6PEI6VK3ijgTZMWLW4y0NaUtADlOdHvC4xAPkRc4nvqCCG3rn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223607; c=relaxed/simple; bh=NJljvBBncSXGFgCAhktMljdBsexiyMgQ3kAEmS7MYjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jQw7NGh1VNLGRcVGFAmUKdFlTlgUdbc7G9kw7Yj4CteTzr+R7X2gL7EBEiSk05i6HcZR7ezeK0M7RrF46Q1AeNYrOtVg6VX65T9GFeAZToeaNeTiy9D1KIrAuDaRdTvfGGRQZV61Tr+bxxsgIh6f5vfDPaLQeAMZ6IXtntBvnO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QhuI+wUR; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QhuI+wUR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716223605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mb47u4BUbRbQvL5WkGQg3GmOK00O3SGgwt1kI14z+kY=; b=QhuI+wURKmG4vu/X//o8LRpSQuBN0aV5TDg+JKp1c4egwax5Okwa9k0ebacWklMwwBz65m 1UeutzwWpgM8G6/2vQle1bVbOXfOsxSXd3upK+s6Nwm/hfhBC3h+PtAcCfxfCEBtGrMJoM mvFr/ZzdQVBwUTlGczVKNDHdMV7YHc0= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-rTwhFBaiNiqt3JQL2V7mVw-1; Mon, 20 May 2024 12:46:43 -0400 X-MC-Unique: rTwhFBaiNiqt3JQL2V7mVw-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a5a05c4e0efso718457666b.1 for ; Mon, 20 May 2024 09:46:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716223602; x=1716828402; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mb47u4BUbRbQvL5WkGQg3GmOK00O3SGgwt1kI14z+kY=; b=BMC3of3Km90U8+rANIndagS/QCMkVK6lvK6bSrcvUnQxa80eo3SpSW0g7bqCDSagW0 rHvAaQK6qu2xyHEn1jE3uUtA3/JL36nSfLpmmDuCMBTbfujfsgeJVhVgph0V7bnX7CW4 sONsJOMIWhMFwrvghNc6Nlz+YsLhNQ9/L1SV+zHPtIqhewy5U0c8Ni6co53HixpEDjGS aE2/bKhGj1ot+O2g9CxKmLbNvisxLyddz/JGhlfbadsSlsW59IbjYFXv+ff+v44x7466 lCEGjTVmLhx7FZCiID+PC4VcFd9fYdLVwi5PSHQu31nZbjg56LBCsenWQ25qcH/UDTx3 8VJg== X-Forwarded-Encrypted: i=1; AJvYcCUP0tlZVwsYfIpAJU1NWTcOq8ncBEIASNxP7paF+gFAKZ0vCecc16pYDczFl1bGgPHpB08iPZMkcP+8Q1QqiM3aJwF1BaXXPoLK X-Gm-Message-State: AOJu0YyQie9IY89h09pR0yK1dTgPlhDDs+Qix1m3m3pFb6eIoSMraX9t gu9re/iurMsF0eI8bMZt/xYsV/gwz4JkyRfOZ4fKwMfe1r8C3AlwjWfK0tw6I0vdDkItlmvulhG FV7BDranHrgCalJPYi8JcmA4nF9qiSqzJJvdbdHHphM8P3kdE4/S6iIz/ X-Received: by 2002:a17:906:1797:b0:a5a:8d07:6a00 with SMTP id a640c23a62f3a-a5a8d076e2cmr1097251566b.64.1716223602257; Mon, 20 May 2024 09:46:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXq/eJmuS+/EKU25zG0+NkD2jNJAjk33AZAKqiESOoaaPGOJRW1cqPS3Ogh8tCt2A0TzJAEg== X-Received: by 2002:a17:906:1797:b0:a5a:8d07:6a00 with SMTP id a640c23a62f3a-a5a8d076e2cmr1097248866b.64.1716223601635; Mon, 20 May 2024 09:46:41 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5df00490cfsm318872066b.159.2024.05.20.09.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 09:46:41 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn , Alexander Viro , Christian Brauner , Jan Kara Subject: [PATCH v2 2/4] fs: add FS_IOC_FSSETXATTRAT and FS_IOC_FSGETXATTRAT Date: Mon, 20 May 2024 18:46:21 +0200 Message-ID: <20240520164624.665269-4-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240520164624.665269-2-aalbersh@redhat.com> References: <20240520164624.665269-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory. The project is created from userspace by opening and calling FS_IOC_FSSETXATTR on each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. as opening them returns a special inode from VFS. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This patch adds two new ioctls which allows userspace, such as xfs_quota, to set project ID on special files by using parent directory to open FS inode. This will let xfs_quota set ID on all inodes and also reset it when project is removed. Also, as vfs_fileattr_set() is now will called on special files too, let's forbid any other attributes except projid and nextents (symlink can have one). Signed-off-by: Andrey Albershteyn --- fs/ioctl.c | 93 +++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 11 +++++ 2 files changed, 104 insertions(+) diff --git a/fs/ioctl.c b/fs/ioctl.c index 1d5abfdf0f22..3e3aacb6ea6e 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "internal.h" @@ -647,6 +648,19 @@ static int fileattr_set_prepare(struct inode *inode, if (fa->fsx_cowextsize == 0) fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE; + /* + * The only use case for special files is to set project ID, forbid any + * other attributes + */ + if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) { + if (fa->fsx_xflags & ~FS_XFLAG_PROJINHERIT) + return -EINVAL; + if (!S_ISLNK(inode->i_mode) && fa->fsx_nextents) + return -EINVAL; + if (fa->fsx_extsize || fa->fsx_cowextsize) + return -EINVAL; + } + return 0; } @@ -763,6 +777,79 @@ static int ioctl_fssetxattr(struct file *file, void __user *argp) return err; } +static int ioctl_fsgetxattrat(struct file *file, void __user *argp) +{ + struct path filepath; + struct fsxattrat fsxat; + struct fileattr fa; + int error; + + if (!S_ISDIR(file_inode(file)->i_mode)) + return -EBADF; + + if (copy_from_user(&fsxat, argp, sizeof(struct fsxattrat))) + return -EFAULT; + + error = user_path_at(fsxat.dfd, fsxat.path, 0, &filepath); + if (error) + return error; + + error = vfs_fileattr_get(filepath.dentry, &fa); + if (error) { + path_put(&filepath); + return error; + } + + fsxat.fsx.fsx_xflags = fa.fsx_xflags; + fsxat.fsx.fsx_extsize = fa.fsx_extsize; + fsxat.fsx.fsx_nextents = fa.fsx_nextents; + fsxat.fsx.fsx_projid = fa.fsx_projid; + fsxat.fsx.fsx_cowextsize = fa.fsx_cowextsize; + + if (copy_to_user(argp, &fsxat, sizeof(struct fsxattrat))) + error = -EFAULT; + + path_put(&filepath); + return error; +} + +static int ioctl_fssetxattrat(struct file *file, void __user *argp) +{ + struct mnt_idmap *idmap = file_mnt_idmap(file); + struct fsxattrat fsxat; + struct path filepath; + struct fileattr fa; + int error; + + if (!S_ISDIR(file_inode(file)->i_mode)) + return -EBADF; + + if (copy_from_user(&fsxat, argp, sizeof(struct fsxattrat))) + return -EFAULT; + + error = user_path_at(fsxat.dfd, fsxat.path, 0, &filepath); + if (error) + return error; + + error = mnt_want_write(filepath.mnt); + if (error) { + path_put(&filepath); + return error; + } + + fileattr_fill_xflags(&fa, fsxat.fsx.fsx_xflags); + fa.fsx_extsize = fsxat.fsx.fsx_extsize; + fa.fsx_nextents = fsxat.fsx.fsx_nextents; + fa.fsx_projid = fsxat.fsx.fsx_projid; + fa.fsx_cowextsize = fsxat.fsx.fsx_cowextsize; + fa.fsx_valid = true; + + error = vfs_fileattr_set(idmap, filepath.dentry, &fa); + mnt_drop_write(filepath.mnt); + path_put(&filepath); + return error; +} + static int ioctl_getfsuuid(struct file *file, void __user *argp) { struct super_block *sb = file_inode(file)->i_sb; @@ -872,6 +959,12 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd, case FS_IOC_FSSETXATTR: return ioctl_fssetxattr(filp, argp); + case FS_IOC_FSGETXATTRAT: + return ioctl_fsgetxattrat(filp, argp); + + case FS_IOC_FSSETXATTRAT: + return ioctl_fssetxattrat(filp, argp); + case FS_IOC_GETFSUUID: return ioctl_getfsuuid(filp, argp); diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 45e4e64fd664..f8cd8d7bf35d 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -139,6 +139,15 @@ struct fsxattr { unsigned char fsx_pad[8]; }; +/* + * Structure passed to FS_IOC_FSGETXATTRAT/FS_IOC_FSSETXATTRAT + */ +struct fsxattrat { + struct fsxattr fsx; /* XATTR to get/set */ + __u32 dfd; /* parent dir */ + const char __user *path; +}; + /* * Flags for the fsx_xflags field */ @@ -231,6 +240,8 @@ struct fsxattr { #define FS_IOC32_SETVERSION _IOW('v', 2, int) #define FS_IOC_FSGETXATTR _IOR('X', 31, struct fsxattr) #define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr) +#define FS_IOC_FSGETXATTRAT _IOR('X', 33, struct fsxattrat) +#define FS_IOC_FSSETXATTRAT _IOW('X', 34, struct fsxattrat) #define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX]) #define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) /* Returns the external filesystem UUID, the same one blkid returns */ From patchwork Mon May 20 16:46:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13668480 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5CDE7C6C6 for ; Mon, 20 May 2024 16:46:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223609; cv=none; b=CE/PEkLp3b9qvLLNRBg+NOQBuommvtNxKRGPN7VE4GwWmRYOLrPXyZFM0c4A25EoSfjA8OAJCmPLVU2QA34HMjIVlBmanBPGxpG1Zjqt/W7k1h5xVYPHLZ9dAhMdYN/CrbahF1JXbptzXtqAc+Kp1qKavW4z5fFkQWRkMrXbPBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223609; c=relaxed/simple; bh=mkrG/YG97IhZX08WJoTg8Am6V3go3zERxJGAAyANROM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k56vgdU+N1A+9pE10R7Po4XLILbHGLKf2Nar0p35ScvDc8dd9pEHRwV/bmqqoTEiKey9Y9pCRBYOLOYCGe8Fjk/UcVj0HBCCrUksSi1ih2NyVZnbhBfowWqXJI3MTCvtI//Cn0J+GJ01HUCHAVxGBZh43Isg+4M0m6nASnrb6hg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HfebAx+E; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HfebAx+E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716223606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8jxKnHArgqISJftS4bn2IeTsfhFcMxrcBBKx2HU6xLc=; b=HfebAx+EVVc+PKOMWQGBLv5wvTmwNcRltS5oCjWXchRLyKWPjGuL1pIRiksp4kIu1c4ixV Y8SZn1/EbUeMErNv5ZnP9qhgDJg9AH/HxV2ZuftTVLRyaYw0SpuzW6G8kP6etptQ8GzR2f Nc0PfvWDvMjQFabElrupmJdpnvb+UXE= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-ZmlfSnnAPOWLMj27yyZhhg-1; Mon, 20 May 2024 12:46:44 -0400 X-MC-Unique: ZmlfSnnAPOWLMj27yyZhhg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a59a0014904so685240766b.2 for ; Mon, 20 May 2024 09:46:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716223603; x=1716828403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8jxKnHArgqISJftS4bn2IeTsfhFcMxrcBBKx2HU6xLc=; b=CEB8f38nVMAGOzblUOQ0Q6YrP+Yvce6aPqya5UQXs5Ns4oOXldj95tHx/R8q5cwCcu ucH0XoJKHZ5dYoYbXHcf973Lo5h41o5l/So90ePqhw6iaEEaAEqsWVOkdp8Pu60Wt75F t8xz9DE40VZ0JTfnB7YAh4mMT4fnz8KkgmVhV2J0DPm4GO8vDK9ZZSaa1JpMj1bJEBqU AJ+EsT57tdqxKH2MnivGFIDff7jjOYX8NYhLUc3xjAa7zi0WhIlu3OVb5FCB079il7GF +D1fMFI3/tDwvly8JqIZ/YQILcJ8xhZU5RqBoppkAjNy3uO5hsz/s32rjiNCIrzdRaJ3 8qjw== X-Forwarded-Encrypted: i=1; AJvYcCUEzKdhdDipi4x5TeC5UvdIdybWQWv8xTZPDdE8v2Go/6GdkbtHYj/aETPaCEc3atlhUgWeKHOGVOwaAW1OllMfNacbGOZPMg4f X-Gm-Message-State: AOJu0YwKhJSO7myoUjtZDWtFxTsK1f7QCBRaDYa59wWi73N0RQxWKCck fMuqoeRIgz5N3x1NiutxDUpTywPy5WUGrOWFJZgBN59G7VYYLRDBqdI/NLO/eDwKkaai1ymZ4bn fmrTsutkC800MBK/l5rQieDlWPy92vYzyx2krknqVsJO2/1MnQrBGt8Tm X-Received: by 2002:a17:906:f6ca:b0:a59:a0ec:e02d with SMTP id a640c23a62f3a-a5a2d53b08emr1642865266b.8.1716223603388; Mon, 20 May 2024 09:46:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKsN1Ca9Oy+VPqruQtdHDZgorMnecfIWweVEvQxfx8HVKUScciqwN5lGVVPqB5e74kDInYWg== X-Received: by 2002:a17:906:f6ca:b0:a59:a0ec:e02d with SMTP id a640c23a62f3a-a5a2d53b08emr1642863466b.8.1716223602811; Mon, 20 May 2024 09:46:42 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5df00490cfsm318872066b.159.2024.05.20.09.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 09:46:42 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn , Chandan Babu R , "Darrick J. Wong" Subject: [PATCH v2 3/4] xfs: allow setting xattrs on special files Date: Mon, 20 May 2024 18:46:22 +0200 Message-ID: <20240520164624.665269-5-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240520164624.665269-2-aalbersh@redhat.com> References: <20240520164624.665269-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As XFS didn't have ioctls for special files setting an inode extended attributes was rejected for them in xfs_fileattr_set(). Same applies for reading. With XFS's project quota directories this is necessary. When project is setup, xfs_quota opens and calls FS_IOC_SETFSXATTR on every inode in the directory. However, special files are skipped due to open() returning a special inode for them. So, they don't even get to this check. The FS_IOC_FS[SET|GET]XATTRAT will call xfs_fileattr_set/get() on a special file. Therefore, allow them to work on special inodes. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_ioctl.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index f0117188f302..adedfcd3fde5 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -459,9 +459,6 @@ xfs_fileattr_get( { struct xfs_inode *ip = XFS_I(d_inode(dentry)); - if (d_is_special(dentry)) - return -ENOTTY; - xfs_ilock(ip, XFS_ILOCK_SHARED); xfs_fill_fsxattr(ip, XFS_DATA_FORK, fa); xfs_iunlock(ip, XFS_ILOCK_SHARED); @@ -736,9 +733,6 @@ xfs_fileattr_set( trace_xfs_ioctl_setattr(ip); - if (d_is_special(dentry)) - return -ENOTTY; - if (!fa->fsx_valid) { if (fa->flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL | FS_NODUMP_FL | From patchwork Mon May 20 16:46:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13668481 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CC7D7C6C6 for ; Mon, 20 May 2024 16:46:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223611; cv=none; b=OsSwuexi6og+UT1gIGNJ1d2Jjxv+9E8SFghCWOHOoHnnbZ0R1Lf+7rC+LG5x9bYzgR8ufgVCadrm0VGTjNHGbAhM/oSXfMb/y2tbFFUgHarXOUj1uCNJv6vtwAowx323tqsAFwGNKsUVhX48WbZ6oAD1jN+A0ncLMSmdE7XYzsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716223611; c=relaxed/simple; bh=vmQ2RZzOAXcMFnAqJwI9gEIKU5whTvVL+1HY9/asXoE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UOqr9OD0FCuAR+FDFY0SH3DVr5qbJsHDmDQrOJXf5NVhS6YSGmR4luvSjGkovor0RVd4AhnIIbmu9847xts8ryanwnNR1wfzpVZbsdAbNOJhImuMpyFo+DYX5/Sg8tidK99VOYKqrmlYs+3x9cKQRFvUbS27KGOs8u+HOAfWCeE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZwDXnjYP; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZwDXnjYP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716223607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ma2q0HaixXoqU+Yv1j7uLrxclgoa/BmHR6s9hlQtBag=; b=ZwDXnjYPtIjqzqum9d2oFscJZHXtygUDhNmKW5GROGLL3wakeS7Z6zqJBdbOpKXYGOtfXJ t7kHNuuHDYE891y5ZrLIzznRoMhQHGeRvZQlwCRi0xV2pZNiyF34eNh/jKdkuauSbEWBkA +/9NHwXnM8jmfHJgkjVSNFXc6T+iI2Q= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-j4oKqbX4OvCKb_aWNKqoYA-1; Mon, 20 May 2024 12:46:45 -0400 X-MC-Unique: j4oKqbX4OvCKb_aWNKqoYA-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a59a17f35c8so732163966b.0 for ; Mon, 20 May 2024 09:46:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716223604; x=1716828404; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ma2q0HaixXoqU+Yv1j7uLrxclgoa/BmHR6s9hlQtBag=; b=tjiItgElgKP8GRMekBgVD9AHJuM/A6Y/ml7z057iWeYQsvZqAHdq7zFW2v1ojfTufC wW4EvH5Nfb203WFQCk+sUoVxb8kG8Z8sfddpUiAdXcpRIfLU3+BshK02kM7lKAX7SxZE 61T9bmv5rBji1iYJDdVyrV2g3Cnlvn7Fr+II363v9RMlpzjm0rgayKyercKg8aw5icMP nmIAf5cGR0KPLy+Crvbm1WhExuEzjFdQT+GXACbigPXsAKHXOsdjen9q9CdoTCypWAxk 59782mggturTewPuLBKBOPKeK8aMTpvy76jawG5VYS4/3NwRS3kbnqFH5JvKTYftGIru hW3g== X-Forwarded-Encrypted: i=1; AJvYcCV5QgcTT6RHDulYNefz8bvaMFM9XtU6oqNZ4AQvM4A2ezWRU5Kfx3k+ionwc0gn7m4fuQ4wVVqUpph7oM++eyLBZ2DUGjIt/VJy X-Gm-Message-State: AOJu0Yy2oihTN+AsKLesi58As2m8qbgtkP/QIS3Pq19jFS4yOTZ9vkCo lAevgjNWBa7wxpAKcEiaI+vQ2/lWPOyqv4NmuUNDxIsd8+2JOtb1EaHdu2WSPNotYpUQxaCowW+ aALW8+HTclxTRr1xiyaYo0qleE99UMO/X3xb66tT2BxQqPpXy19qKnBcF X-Received: by 2002:a17:906:6882:b0:a5a:76e2:c2a8 with SMTP id a640c23a62f3a-a5a76e2c306mr1371370766b.23.1716223604180; Mon, 20 May 2024 09:46:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQbzL2IUZ7TqGYW7K+SSSR6MaHYKue61QHFUN9QosNc5m8X+OJnkD30A35E9ai6IfJjIfNcw== X-Received: by 2002:a17:906:6882:b0:a5a:76e2:c2a8 with SMTP id a640c23a62f3a-a5a76e2c306mr1371369166b.23.1716223603727; Mon, 20 May 2024 09:46:43 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5df00490cfsm318872066b.159.2024.05.20.09.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 09:46:43 -0700 (PDT) From: Andrey Albershteyn To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org Cc: Andrey Albershteyn , Chandan Babu R , "Darrick J. Wong" Subject: [PATCH v2 4/4] xfs: add fileattr_set/get for symlinks Date: Mon, 20 May 2024 18:46:23 +0200 Message-ID: <20240520164624.665269-6-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240520164624.665269-2-aalbersh@redhat.com> References: <20240520164624.665269-2-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As there are now FS_IOC_FS[GET|SET]XATTRAT ioctls, xfs_quota will call them on special files. These new ioctls call ->xfs_fileattr_set/get. Symlink inodes don't have operations to set extended attributes, so add ones used by other inodes. The attribute value combinations are checked in fileattr_set_prepare(). Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_iops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index ff222827e550..63f1a055a64a 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -1199,6 +1199,8 @@ static const struct inode_operations xfs_symlink_inode_operations = { .setattr = xfs_vn_setattr, .listxattr = xfs_vn_listxattr, .update_time = xfs_vn_update_time, + .fileattr_get = xfs_fileattr_get, + .fileattr_set = xfs_fileattr_set, }; /* Figure out if this file actually supports DAX. */