From patchwork Thu Feb 27 21:33:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11410263 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C5B592A for ; Thu, 27 Feb 2020 21:33:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2ABF024677 for ; Thu, 27 Feb 2020 21:33:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="e5Umj30j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729944AbgB0Vdq (ORCPT ); Thu, 27 Feb 2020 16:33:46 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:44690 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbgB0Vdq (ORCPT ); Thu, 27 Feb 2020 16:33:46 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01RLO7EN160078; Thu, 27 Feb 2020 21:33:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=gG8N/ZZ/oNWL1TJdw/TGNSOtJpIZs1TYnGMlRyZuD54=; b=e5Umj30jJwT8YSMsEOYZ5DpzAr6BhvFscrgileqANDABJSnmwaoC15xYYaKp07S3ZqXr rjvUO3tN4L3VnUpotuomMQf2MsW1GTlqP2uvq2kevRocwfovHMDotsD6qC7OdKxqxdNa mH4kLBL+tANNhlzL9x4W+eFcFRuTGz0KSsmBD0tWzl40QUzuQTV2BnE13KmI615V7U/O vsVNv3678hcrs99Kimypi6z1RaOJKtlsIv9Ij9N+Rg31b9uQ5Rd9R18xQfR4YljdpsS8 BOH/b21otjky4gLcAq0yCtk9nKC40BwnnV+ksB25g0yPgGQJjbJ0GuNm2T4k5r5JVdiI 9w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2yehxrsbfr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Feb 2020 21:33:44 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01RLGLgW050238; Thu, 27 Feb 2020 21:33:44 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2ydcsauv4v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Feb 2020 21:33:44 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01RLXhgH008676; Thu, 27 Feb 2020 21:33:43 GMT Received: from localhost (/10.145.179.117) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 27 Feb 2020 13:33:42 -0800 Subject: [PATCH 1/3] vfs: create ioctls to query and set the filesystem uuids From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Date: Thu, 27 Feb 2020 13:33:41 -0800 Message-ID: <158283922171.904118.10312419179350062263.stgit@magnolia> In-Reply-To: <158283921562.904118.13877489081184026686.stgit@magnolia> References: <158283921562.904118.13877489081184026686.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9544 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=1 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002270142 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9544 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 priorityscore=1501 bulkscore=0 phishscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=1 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002270142 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Define a pair of ioctls to get and set the filesystem uuid. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_fs.h | 2 ++ include/uapi/linux/fs.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 558a396c74b3..c968eaf56ec3 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -814,6 +814,8 @@ struct xfs_scrub_metadata { #define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom) #define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req) #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +/* FS_IOC_GETFSUUID ----------- uses 129 */ +/* FS_IOC_SETFSUUID ----------- uses 130 */ /* XFS_IOC_GETFSUUID ---------- deprecated 140 */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 379a612f8f1d..a5423d540ecd 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -142,6 +142,32 @@ struct fsxattr { #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */ #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ +/* Get and set filesystem UUID. */ +struct ioc_fsuuid { + uint32_t fu_flags; + uint16_t fu_length; + uint16_t fu_reserved; + uint64_t fu_reserved1; +}; + +/* + * Set the UUID even if that would require setting of an incompat or rocompat + * feature flag. This will make the filesystem unmountable on older kernels. + */ +#define FS_IOC_SETFSUUID_FORCE_INCOMPAT (1 << 0) + +#define FS_IOC_SETFSUUID_ALL (FS_IOC_SETFSUUID_FORCE_INCOMPAT) + +static inline size_t ioc_fsuuid_sizeof(size_t payload_len) +{ + return sizeof(struct ioc_fsuuid) + payload_len; +} + +static inline char *ioc_fsuuid_payload(struct ioc_fsuuid *fu) +{ + return (char *)(fu + 1); +} + /* the read-only stuff doesn't really belong here, but any other place is probably as bad and I don't want to create yet another include file. */ @@ -214,6 +240,8 @@ struct fsxattr { #define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr) #define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX]) #define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) +#define FS_IOC_GETFSUUID _IOR('X', 129, struct ioc_fsuuid) +#define FS_IOC_SETFSUUID _IOW('X', 130, struct ioc_fsuuid) /* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) From patchwork Thu Feb 27 21:33:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11410273 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E193792A for ; Thu, 27 Feb 2020 21:33:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6E25246A1 for ; Thu, 27 Feb 2020 21:33:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="VBej/J64" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730053AbgB0Vdx (ORCPT ); Thu, 27 Feb 2020 16:33:53 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:46278 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbgB0Vdx (ORCPT ); Thu, 27 Feb 2020 16:33:53 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01RLNiV1195538; Thu, 27 Feb 2020 21:33:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=LeO4b8BoftObGHpnYTNWh7068zE+UmbEf+8MLdUVGD0=; b=VBej/J64cPznzvVHCCsWh5ITHaJT/SInk3NmtcKQCdlUqJPIwgrLrhqasYJhJO0RxsG/ i86GoTvCeYri/nh0OMZ3gSyMF+33e8S4mMovVvy6G7U4ZyCdeoh6HeO8bX79lAei58Gu jFYnupuS150vpQn2vD+cyN3Yaw/KhgmxCTBwyvjDJZJqItLZa2vJJFDMfIwDNgGSijXz 3KCn3YdY3YKeAmn9GslHYyIrC7S/e2luliormvxu+1ow2pF7Uaafkg8w0W+rGhh17DKb uPS5AeLn3KZ4Tb1gXq8fiWN9OM9NK0wlKjO+RnyiGR/y1vgfs71u7aQNwloDMZjeTxO8 eA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2ydcsnnt6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Feb 2020 21:33:51 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01RLGiBM015387; Thu, 27 Feb 2020 21:33:50 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ydcsde6u8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Feb 2020 21:33:50 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01RLXnUP008806; Thu, 27 Feb 2020 21:33:49 GMT Received: from localhost (/10.145.179.117) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 27 Feb 2020 13:33:48 -0800 Subject: [PATCH 2/3] xfs: allow online filesystem uuid queries From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Date: Thu, 27 Feb 2020 13:33:48 -0800 Message-ID: <158283922839.904118.7827625132603295868.stgit@magnolia> In-Reply-To: <158283921562.904118.13877489081184026686.stgit@magnolia> References: <158283921562.904118.13877489081184026686.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9544 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 suspectscore=3 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002270142 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9544 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 suspectscore=3 impostorscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002270142 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Wire up the new ioctls to get and set xfs filesystem uuids. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_ioctl.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_mount.c | 30 +++++++++-- fs/xfs/xfs_mount.h | 3 + 3 files changed, 169 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index b4f5851e2ca5..66bd96d900cf 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1960,6 +1960,142 @@ xfs_fs_eofblocks_from_user( return 0; } +static inline int +xfs_ioc_getfsuuid( + struct xfs_mount *mp, + struct ioc_fsuuid __user *user_fu) +{ + struct ioc_fsuuid fu; + + if (copy_from_user(&fu, user_fu, sizeof(fu))) + return -EFAULT; + + if (fu.fu_reserved || fu.fu_reserved1 || fu.fu_flags) + return -EINVAL; + + if (fu.fu_length == 0) { + fu.fu_length = sizeof(uuid_t); + goto out; + } + + if (fu.fu_length < sizeof(uuid_t)) + return -EINVAL; + + if (copy_to_user(user_fu + 1, &mp->m_super->s_uuid, sizeof(uuid_t))) + return -EFAULT; + fu.fu_length = sizeof(uuid_t); + +out: + if (copy_to_user(user_fu, &fu, sizeof(fu))) + return -EFAULT; + return 0; +} + +static inline int +xfs_ioc_setfsuuid( + struct file *filp, + struct xfs_mount *mp, + struct ioc_fsuuid __user *user_fu) +{ + struct ioc_fsuuid fu; + uuid_t old_uuid; + uuid_t new_uuid; + uuid_t *forget_uuid = NULL; + int error; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (copy_from_user(&fu, user_fu, sizeof(fu))) + return -EFAULT; + + if (fu.fu_reserved || fu.fu_reserved1 || + (fu.fu_flags & ~FS_IOC_SETFSUUID_ALL) || + fu.fu_length != sizeof(uuid_t)) + return -EINVAL; + + if (copy_from_user(&new_uuid, user_fu + 1, sizeof(uuid_t))) + return -EFAULT; + if (uuid_is_null(&new_uuid)) + return -EINVAL; + + error = mnt_want_write_file(filp); + if (error) + return error; + + /* Save a slot in the uuid table, if desired. */ + if (!(mp->m_flags & XFS_MOUNT_NOUUID)) { + error = xfs_uuid_remember(&new_uuid); + if (error) + goto out_drop_write; + forget_uuid = &new_uuid; + } + + spin_lock(&mp->m_sb_lock); + uuid_copy(&old_uuid, &mp->m_sb.sb_uuid); + + /* + * Before v5, the uuid was only set in the superblock, so all we need + * to do here is update the incore sb and write that out to disk. + * + * On a v5 filesystem, every metadata object has a uuid stamped into + * the header. The particular uuid used is either sb_uuid or + * sb_meta_uuid, depending on whether the meta_uuid feature is set. + * + * If the meta_uuid feature is set and the new uuid matches the + * meta_uuid, then we'll deactivate the feature and set sb_uuid to the + * new uuid. + * + * If the meta_uuid feature is not set, the new uuid does not match the + * existing sb_uuid, we need to turn on the meta_uuid feature. If + * userspace did not set FORCE_INCOMPAT we have to bail out. + * Otherwise, copy sb_uuid to sb_meta_uuid, set the meta_uuid feature + * bit, and set sb_uuid to the new uuid. + */ + if (xfs_sb_version_hasmetauuid(&mp->m_sb) && + uuid_equal(&new_uuid, &mp->m_sb.sb_meta_uuid)) { + mp->m_sb.sb_features_incompat &= ~XFS_SB_FEAT_INCOMPAT_META_UUID; + } else if (xfs_sb_version_hascrc(&mp->m_sb) && + !xfs_sb_version_hasmetauuid(&mp->m_sb) && + !uuid_equal(&new_uuid, &mp->m_sb.sb_uuid)) { + if (!(fu.fu_flags & FS_IOC_SETFSUUID_FORCE_INCOMPAT)) { + spin_unlock(&mp->m_sb_lock); + error = -EOPNOTSUPP; + goto out_drop_uuid; + } + uuid_copy(&mp->m_sb.sb_meta_uuid, &mp->m_sb.sb_uuid); + mp->m_sb.sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_META_UUID; + } + uuid_copy(&mp->m_sb.sb_uuid, &new_uuid); + spin_unlock(&mp->m_sb_lock); + + error = xfs_sync_sb_buf(mp); + if (error) + goto out_drop_uuid; + + /* Update incore state and prepare to drop the old uuid. */ + uuid_copy(&mp->m_super->s_uuid, &new_uuid); + if (!(mp->m_flags & XFS_MOUNT_NOUUID)) + forget_uuid = &old_uuid; + + /* + * Update the secondary supers, being aware that growfs also updates + * backup supers so we need to lock against that. + */ + mutex_lock(&mp->m_growlock); + error = xfs_update_secondary_sbs(mp); + mutex_unlock(&mp->m_growlock); + + invalidate_bdev(mp->m_ddev_targp->bt_bdev); + +out_drop_uuid: + if (forget_uuid) + xfs_uuid_forget(forget_uuid); +out_drop_write: + mnt_drop_write_file(filp); + return error; +} + /* * Note: some of the ioctl's return positive numbers as a * byte count indicating success, such as readlink_by_handle. @@ -2246,6 +2382,11 @@ xfs_file_ioctl( return xfs_icache_free_eofblocks(mp, &keofb); } + case FS_IOC_GETFSUUID: + return xfs_ioc_getfsuuid(mp, arg); + case FS_IOC_SETFSUUID: + return xfs_ioc_setfsuuid(filp, mp, arg); + default: return -ENOTTY; } diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index e097cece492f..8acd9cffcf50 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -58,7 +58,7 @@ xfs_uuid_mount( struct xfs_mount *mp) { uuid_t *uuid = &mp->m_sb.sb_uuid; - int hole, i; + int error; /* Publish UUID in struct super_block */ uuid_copy(&mp->m_super->s_uuid, uuid); @@ -71,6 +71,21 @@ xfs_uuid_mount( return -EINVAL; } + error = xfs_uuid_remember(uuid); + if (!error) + return 0; + + xfs_warn(mp, "Filesystem has duplicate UUID %pU - can't mount", uuid); + return error; +} + +int +xfs_uuid_remember( + const uuid_t *uuid) +{ + int hole; + int i; + mutex_lock(&xfs_uuid_table_mutex); for (i = 0, hole = -1; i < xfs_uuid_table_size; i++) { if (uuid_is_null(&xfs_uuid_table[i])) { @@ -94,7 +109,6 @@ xfs_uuid_mount( out_duplicate: mutex_unlock(&xfs_uuid_table_mutex); - xfs_warn(mp, "Filesystem has duplicate UUID %pU - can't mount", uuid); return -EINVAL; } @@ -102,12 +116,18 @@ STATIC void xfs_uuid_unmount( struct xfs_mount *mp) { - uuid_t *uuid = &mp->m_sb.sb_uuid; - int i; - if (mp->m_flags & XFS_MOUNT_NOUUID) return; + xfs_uuid_forget(&mp->m_sb.sb_uuid); +} + +void +xfs_uuid_forget( + const uuid_t *uuid) +{ + int i; + mutex_lock(&xfs_uuid_table_mutex); for (i = 0; i < xfs_uuid_table_size; i++) { if (uuid_is_null(&xfs_uuid_table[i])) diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 95ee6b898d3d..df6a7a703fe1 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -448,4 +448,7 @@ void xfs_force_summary_recalc(struct xfs_mount *mp); void xfs_mod_delalloc(struct xfs_mount *mp, int64_t delta); unsigned int xfs_guess_metadata_threads(struct xfs_mount *mp); +int xfs_uuid_remember(const uuid_t *uuid); +void xfs_uuid_forget(const uuid_t *uuid); + #endif /* __XFS_MOUNT_H__ */ From patchwork Thu Feb 27 21:33:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11410281 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 595C0138D for ; Thu, 27 Feb 2020 21:34:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F62A24677 for ; Thu, 27 Feb 2020 21:34:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="lT5SdL84" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729924AbgB0VeA (ORCPT ); Thu, 27 Feb 2020 16:34:00 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:43810 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbgB0VeA (ORCPT ); Thu, 27 Feb 2020 16:34:00 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01RLMpsU030108; Thu, 27 Feb 2020 21:33:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=SK3ORLcKLc32g22nLM5e6u2awazlkXAzyNrheC/M/BA=; b=lT5SdL84B4X3pWTeDR0nkPy5ugvzX8hus7R1OMp/2Bm/Crus2nfbx5DOs7IezcH/6IwS tR4fTgOPDF+iSnaBoY/c6d4P8Zxi79tNQFR6tQj6fPEkfMNyawQkHimbRgbnwYWG3yDL +MiHLGI1/TLX/rEaOi67VKHg4yy2RGVfZjQChzjkzHBMYFsRvelgVUF7DaUdCwMCUQew wz+Fb8NpAnu2n1MZtEUTQc+1aJ5NB903eA/f+XI83aU4UjKjhHz+BBw4HZAv+HfmzDHE r/lTWG6tFZlmooZawAY3GAttgzNVqj/RGhpchG5H9ry9N3SeI1vPL3rgZFLgmfzHhD4L pg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2ydct3ds5g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Feb 2020 21:33:59 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01RLIIK4052026; Thu, 27 Feb 2020 21:33:58 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2ydcs6bw07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Feb 2020 21:33:58 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01RLXvef008864; Thu, 27 Feb 2020 21:33:58 GMT Received: from localhost (/10.145.179.117) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 27 Feb 2020 13:33:57 -0800 Subject: [PATCH 3/3] ext4: allow online filesystem uuid queries From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Date: Thu, 27 Feb 2020 13:33:54 -0800 Message-ID: <158283923456.904118.14244827054399587376.stgit@magnolia> In-Reply-To: <158283921562.904118.13877489081184026686.stgit@magnolia> References: <158283921562.904118.13877489081184026686.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9544 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=1 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002270142 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9544 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 spamscore=0 priorityscore=1501 malwarescore=0 adultscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=1 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002270142 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Wire up the new ioctls to get and set the ext4 filesystem uuid. Signed-off-by: Darrick J. Wong --- fs/ext4/ioctl.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index a0ec750018dd..c8d556c93cc7 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -813,6 +813,132 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg) return error; } +static int ext4_ioc_getfsuuid(struct super_block *sb, + struct ioc_fsuuid __user *user_fu) +{ + struct ioc_fsuuid fu; + struct ext4_super_block *es = EXT4_SB(sb)->s_es; + + BUILD_BUG_ON(sizeof(es->s_uuid) != sizeof(uuid_t)); + + if (copy_from_user(&fu, user_fu, sizeof(fu))) + return -EFAULT; + + if (fu.fu_reserved || fu.fu_reserved1 || fu.fu_flags) + return -EINVAL; + + if (fu.fu_length == 0) { + fu.fu_length = sizeof(es->s_uuid); + goto out; + } + + if (fu.fu_length < sizeof(es->s_uuid)) + return -EINVAL; + + if (copy_to_user(user_fu + 1, es->s_uuid, sizeof(es->s_uuid))) + return -EFAULT; + fu.fu_length = sizeof(es->s_uuid); + +out: + if (copy_to_user(user_fu, &fu, sizeof(fu))) + return -EFAULT; + return 0; +} + +static int ext4_ioc_setfsuuid(struct file *filp, struct super_block *sb, + struct ioc_fsuuid __user *user_fu) +{ + struct ioc_fsuuid fu; + uuid_t new_uuid; + struct ext4_sb_info *sbi = EXT4_SB(sb); + handle_t *handle; + int err, err2; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (copy_from_user(&fu, user_fu, sizeof(fu))) + return -EFAULT; + + if (fu.fu_reserved || fu.fu_reserved1 || + (fu.fu_flags & ~FS_IOC_SETFSUUID_ALL) || + fu.fu_length != sizeof(uuid_t)) + return -EINVAL; + + if (copy_from_user(&new_uuid, user_fu + 1, sizeof(uuid_t))) + return -EFAULT; + if (uuid_is_null(&new_uuid)) + return -EINVAL; + + err = mnt_want_write_file(filp); + if (err) + return err; + + handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, 1); + if (IS_ERR(handle)) { + err = PTR_ERR(handle); + goto out_drop_write; + } + err = ext4_journal_get_write_access(handle, sbi->s_sbh); + if (err) + goto out_cancel_trans; + + /* + * Older ext4 filesystems with the group descriptor checksum feature + * but not the general metadata checksum features require all group + * descriptors to be rewritten to change the UUID. We can't do that + * here, so just bail out. + */ + if (ext4_has_feature_gdt_csum(sb) && !ext4_has_metadata_csum(sb)) { + err = -EOPNOTSUPP; + goto out_cancel_trans; + } + + /* + * Prior to the addition of metadata checksumming, the uuid was only + * used in the superblock, so for those filesystems, all we need to do + * here is update the incore uuid and write the super to disk. + * + * On a metadata_csum filesystem, every metadata object has a checksum + * that is seeded with the checksum of the uuid that was set at + * mkfs time. The seed value can be stored in the ondisk superblock + * or computed at mount time, depending on feature flags. + * + * If the csum_seed feature is not set, we need to turn on the + * csum_seed feature. If userspace did not set FORCE_INCOMPAT we have + * to bail out. Otherwise, copy the incore checksum seed to the ondisk + * superblock, set the csum_seed feature bit, and then we can update + * the incore uuid. + */ + if ((ext4_has_metadata_csum(sb) || ext4_has_feature_ea_inode(sb)) && + !ext4_has_feature_csum_seed(sb) && + memcmp(&new_uuid, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid))) { + if (!(fu.fu_flags & FS_IOC_SETFSUUID_FORCE_INCOMPAT)) { + err = -EOPNOTSUPP; + goto out_cancel_trans; + } + sbi->s_es->s_checksum_seed = cpu_to_le32(sbi->s_csum_seed); + ext4_set_feature_csum_seed(sb); + } + memcpy(sbi->s_es->s_uuid, &new_uuid, sizeof(uuid_t)); + + err = ext4_handle_dirty_super(handle, sb); + if (err) + goto out_cancel_trans; + + /* Update incore state. */ + uuid_copy(&sb->s_uuid, &new_uuid); + invalidate_bdev(sb->s_bdev); + +out_cancel_trans: + err2 = ext4_journal_stop(handle); + if (!err) + err = err2; +out_drop_write: + mnt_drop_write_file(filp); + return err; +} + long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct inode *inode = file_inode(filp); @@ -1304,6 +1430,12 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return -EOPNOTSUPP; return fsverity_ioctl_measure(filp, (void __user *)arg); + case FS_IOC_GETFSUUID: + return ext4_ioc_getfsuuid(sb, (struct ioc_fsuuid __user *)arg); + case FS_IOC_SETFSUUID: + return ext4_ioc_setfsuuid(filp, sb, + (struct ioc_fsuuid __user *)arg); + default: return -ENOTTY; }