blob: 2ec1d8a27352e6a8595af8cbaecbfc9390e16cdd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_dmapi.h"
28#include "xfs_mount.h"
Tim Shimmin4cd4a032005-09-05 08:24:10 +100029#include "xfs_quota.h"
30#include "xfs_error.h"
Christoph Hellwigb09cc772007-08-30 17:19:57 +100031#include "xfs_clnt.h"
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34STATIC struct xfs_dquot *
35xfs_dqvopchown_default(
36 struct xfs_trans *tp,
37 struct xfs_inode *ip,
38 struct xfs_dquot **dqp,
39 struct xfs_dquot *dq)
40{
41 return NULL;
42}
43
Tim Shimmin4cd4a032005-09-05 08:24:10 +100044/*
45 * Clear the quotaflags in memory and in the superblock.
46 */
47int
48xfs_mount_reset_sbqflags(xfs_mount_t *mp)
49{
50 int error;
51 xfs_trans_t *tp;
52 unsigned long s;
53
54 mp->m_qflags = 0;
55 /*
56 * It is OK to look at sb_qflags here in mount path,
57 * without SB_LOCK.
58 */
59 if (mp->m_sb.sb_qflags == 0)
60 return 0;
61 s = XFS_SB_LOCK(mp);
62 mp->m_sb.sb_qflags = 0;
63 XFS_SB_UNLOCK(mp, s);
64
65 /*
66 * if the fs is readonly, let the incore superblock run
67 * with quotas off but don't flush the update out to disk
68 */
Christoph Hellwigbd186aa2007-08-30 17:21:12 +100069 if (mp->m_flags & XFS_MOUNT_RDONLY)
Tim Shimmin4cd4a032005-09-05 08:24:10 +100070 return 0;
71#ifdef QUOTADEBUG
72 xfs_fs_cmn_err(CE_NOTE, mp, "Writing superblock quota changes");
73#endif
74 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SBCHANGE);
75 if ((error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
76 XFS_DEFAULT_LOG_COUNT))) {
77 xfs_trans_cancel(tp, 0);
78 xfs_fs_cmn_err(CE_ALERT, mp,
79 "xfs_mount_reset_sbqflags: Superblock update failed!");
80 return error;
81 }
82 xfs_mod_sb(tp, XFS_SB_QFLAGS);
Eric Sandeen1c72bf92007-05-08 13:48:42 +100083 error = xfs_trans_commit(tp, 0);
Tim Shimmin4cd4a032005-09-05 08:24:10 +100084 return error;
85}
86
87STATIC int
88xfs_noquota_init(
89 xfs_mount_t *mp,
90 uint *needquotamount,
91 uint *quotaflags)
92{
93 int error = 0;
94
95 *quotaflags = 0;
96 *needquotamount = B_FALSE;
97
98 ASSERT(!XFS_IS_QUOTA_ON(mp));
99
100 /*
101 * If a file system had quotas running earlier, but decided to
102 * mount without -o uquota/pquota/gquota options, revoke the
103 * quotachecked license.
104 */
105 if (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT) {
106 cmn_err(CE_NOTE,
107 "XFS resetting qflags for filesystem %s",
108 mp->m_fsname);
109
110 error = xfs_mount_reset_sbqflags(mp);
111 }
112 return error;
113}
114
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000115static struct xfs_qmops xfs_qmcore_stub = {
Tim Shimmin4cd4a032005-09-05 08:24:10 +1000116 .xfs_qminit = (xfs_qminit_t) xfs_noquota_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .xfs_qmdone = (xfs_qmdone_t) fs_noerr,
118 .xfs_qmmount = (xfs_qmmount_t) fs_noerr,
119 .xfs_qmunmount = (xfs_qmunmount_t) fs_noerr,
120 .xfs_dqrele = (xfs_dqrele_t) fs_noerr,
121 .xfs_dqattach = (xfs_dqattach_t) fs_noerr,
122 .xfs_dqdetach = (xfs_dqdetach_t) fs_noerr,
123 .xfs_dqpurgeall = (xfs_dqpurgeall_t) fs_noerr,
124 .xfs_dqvopalloc = (xfs_dqvopalloc_t) fs_noerr,
125 .xfs_dqvopcreate = (xfs_dqvopcreate_t) fs_noerr,
126 .xfs_dqvoprename = (xfs_dqvoprename_t) fs_noerr,
127 .xfs_dqvopchown = xfs_dqvopchown_default,
128 .xfs_dqvopchownresv = (xfs_dqvopchownresv_t) fs_noerr,
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000129 .xfs_dqstatvfs = (xfs_dqstatvfs_t) fs_noval,
130 .xfs_dqsync = (xfs_dqsync_t) fs_noerr,
131 .xfs_quotactl = (xfs_quotactl_t) fs_nosys,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132};
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000133
134int
135xfs_qmops_get(struct xfs_mount *mp, struct xfs_mount_args *args)
136{
137 if (args->flags & (XFSMNT_UQUOTA | XFSMNT_PQUOTA | XFSMNT_GQUOTA)) {
Christoph Hellwigc8fcfac2007-10-19 16:57:01 +1000138#ifdef CONFIG_XFS_QUOTA
139 mp->m_qm_ops = &xfs_qmcore_xfs;
140#else
141 cmn_err(CE_WARN,
142 "XFS: qouta support not available in this kernel.");
143 return EINVAL;
144#endif
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000145 } else {
146 mp->m_qm_ops = &xfs_qmcore_stub;
147 }
148
149 return 0;
150}
151
152void
153xfs_qmops_put(struct xfs_mount *mp)
154{
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000155}