]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: support metadir quotas
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:42 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:35 +0000 (18:01 -0800)
Support finding the quota files in the metadata directory.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/dquot.c
libxfs/libxfs_api_defs.h

index 338d064995155ed598dc187def559d3b8b3faf42..d2c76fd70bf1a6a30699dad17f8657c4cee560df 100644 (file)
@@ -81,6 +81,41 @@ dquot_help(void)
 {
 }
 
+static xfs_ino_t
+dqtype_to_inode(
+       struct xfs_mount        *mp,
+       xfs_dqtype_t            type)
+{
+       struct xfs_trans        *tp;
+       struct xfs_inode        *dp = NULL;
+       struct xfs_inode        *ip;
+       xfs_ino_t               ret = NULLFSINO;
+       int                     error;
+
+       error = -libxfs_trans_alloc_empty(mp, &tp);
+       if (error)
+               return NULLFSINO;
+
+       if (xfs_has_metadir(mp)) {
+               error = -libxfs_dqinode_load_parent(tp, &dp);
+               if (error)
+                       goto out_cancel;
+       }
+
+       error = -libxfs_dqinode_load(tp, dp, type, &ip);
+       if (error)
+               goto out_dp;
+
+       ret = ip->i_ino;
+       libxfs_irele(ip);
+out_dp:
+       if (dp)
+               libxfs_irele(dp);
+out_cancel:
+       libxfs_trans_cancel(tp);
+       return ret;
+}
+
 static int
 dquot_f(
        int             argc,
@@ -88,8 +123,7 @@ dquot_f(
 {
        bmap_ext_t      bm;
        int             c;
-       int             dogrp;
-       int             doprj;
+       xfs_dqtype_t    type = XFS_DQTYPE_USER;
        xfs_dqid_t      id;
        xfs_ino_t       ino;
        xfs_extnum_t    nex;
@@ -97,38 +131,33 @@ dquot_f(
        int             perblock;
        xfs_fileoff_t   qbno;
        int             qoff;
-       char            *s;
+       const char      *s;
 
-       dogrp = doprj = optind = 0;
+       optind = 0;
        while ((c = getopt(argc, argv, "gpu")) != EOF) {
                switch (c) {
                case 'g':
-                       dogrp = 1;
-                       doprj = 0;
+                       type = XFS_DQTYPE_GROUP;
                        break;
                case 'p':
-                       doprj = 1;
-                       dogrp = 0;
+                       type = XFS_DQTYPE_PROJ;
                        break;
                case 'u':
-                       dogrp = doprj = 0;
+                       type = XFS_DQTYPE_USER;
                        break;
                default:
                        dbprintf(_("bad option for dquot command\n"));
                        return 0;
                }
        }
-       s = doprj ? _("project") : dogrp ? _("group") : _("user");
+
+       s = libxfs_dqinode_path(type);
        if (optind != argc - 1) {
                dbprintf(_("dquot command requires one %s id argument\n"), s);
                return 0;
        }
-       ino = mp->m_sb.sb_uquotino;
-       if (doprj)
-               ino = mp->m_sb.sb_pquotino;
-       else if (dogrp)
-               ino = mp->m_sb.sb_gquotino;
 
+       ino = dqtype_to_inode(mp, type);
        if (ino == 0 || ino == NULLFSINO) {
                dbprintf(_("no %s quota inode present\n"), s);
                return 0;
index a8416dfbb27f591405888436cab33733bbeb0a30..6b2dc7a30d25472c76bb943cf5f00d828dcebbf0 100644 (file)
 #define xfs_dir_replace                        libxfs_dir_replace
 
 #define xfs_dqblk_repair               libxfs_dqblk_repair
+#define xfs_dqinode_load               libxfs_dqinode_load
+#define xfs_dqinode_load_parent                libxfs_dqinode_load_parent
+#define xfs_dqinode_mkdir_parent       libxfs_dqinode_mkdir_parent
+#define xfs_dqinode_metadir_create     libxfs_dqinode_metadir_create
+#define xfs_dqinode_metadir_link       libxfs_dqinode_metadir_link
+#define xfs_dqinode_path               libxfs_dqinode_path
 #define xfs_dquot_from_disk_ts         libxfs_dquot_from_disk_ts
 #define xfs_dquot_verify               libxfs_dquot_verify