annotate src/plugins/quota/quota-fs.c @ 7086:7ed926ed7aa4 HEAD

Updated copyright notices to include year 2008.
author Timo Sirainen <tss@iki.fi>
date Tue, 01 Jan 2008 22:05:21 +0200
parents 414c9d631a81
children e6693a0ec8e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7086
7ed926ed7aa4 Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
1 /* Copyright (c) 2005-2008 Dovecot authors, see the included COPYING file */
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 /* Only for reporting filesystem quota */
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "lib.h"
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
6 #include "array.h"
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "str.h"
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
8 #include "mountpoint.h"
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "quota-private.h"
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "quota-fs.h"
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #ifdef HAVE_FS_QUOTA
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include <stdio.h>
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <stdlib.h>
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
16 #include <fcntl.h>
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <unistd.h>
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include <sys/stat.h>
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
19 #ifdef HAVE_LINUX_DQBLK_XFS_H
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
20 # include <linux/dqblk_xfs.h>
4565
a54558861acc Check for XFS quota also from xfs/xqm.h
Timo Sirainen <tss@iki.fi>
parents: 4552
diff changeset
21 # define HAVE_XFS_QUOTA
a54558861acc Check for XFS quota also from xfs/xqm.h
Timo Sirainen <tss@iki.fi>
parents: 4552
diff changeset
22 #elif defined (HAVE_XFS_XQM_H)
a54558861acc Check for XFS quota also from xfs/xqm.h
Timo Sirainen <tss@iki.fi>
parents: 4552
diff changeset
23 # include <xfs/xqm.h> /* CentOS 4.x at least uses this */
a54558861acc Check for XFS quota also from xfs/xqm.h
Timo Sirainen <tss@iki.fi>
parents: 4552
diff changeset
24 # define HAVE_XFS_QUOTA
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
25 #endif
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
6159
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
27 #ifdef HAVE_RQUOTA
6439
b951f3e42322 Yet another try at getting rquota code compiling properly with BSD make.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
28 # include "rquota.h"
6159
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
29 # define RQUOTA_GETQUOTA_TIMEOUT_SECS 10
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
30 #endif
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
31
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
32 #ifndef DEV_BSIZE
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
33 # define DEV_BSIZE 512
3762
4d44a337ac08 Fixed to work with struct dqblk.dqb_curspace also which is apparently the
Timo Sirainen <tss@iki.fi>
parents: 3751
diff changeset
34 #endif
4d44a337ac08 Fixed to work with struct dqblk.dqb_curspace also which is apparently the
Timo Sirainen <tss@iki.fi>
parents: 3751
diff changeset
35
4552
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
36 #ifdef HAVE_STRUCT_DQBLK_CURSPACE
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
37 # define dqb_curblocks dqb_curspace
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
38 #endif
ef71b2fdd433 Put back specific checks for struct dqblk.dqb_curblocks vs curspace. The
Timo Sirainen <tss@iki.fi>
parents: 4547
diff changeset
39
4547
912e6d3053e8 Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1
Timo Sirainen <tss@iki.fi>
parents: 4530
diff changeset
40 /* Older sys/quota.h doesn't define _LINUX_QUOTA_VERSION at all, which means
912e6d3053e8 Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1
Timo Sirainen <tss@iki.fi>
parents: 4530
diff changeset
41 it supports only v1 quota */
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
42 #ifndef _LINUX_QUOTA_VERSION
4547
912e6d3053e8 Default _LINUX_QUOTA_VERSION to 1 instead of 2, since older Linux v1
Timo Sirainen <tss@iki.fi>
parents: 4530
diff changeset
43 # define _LINUX_QUOTA_VERSION 1
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
44 #endif
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
45
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
46 struct fs_quota_mountpoint {
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
47 int refcount;
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
48
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
49 char *mount_path;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
50 char *device_path;
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
51 char *type;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
53 #ifdef FS_QUOTA_SOLARIS
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
54 int fd;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
55 char *path;
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
56 #endif
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
57 };
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
58
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
59 struct fs_quota_root {
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 struct quota_root root;
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
61 char *storage_mount_path;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
62
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
63 uid_t uid;
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
64 gid_t gid;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
65 struct fs_quota_mountpoint *mount;
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
66
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
67 unsigned int inode_per_mail:1;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
68 unsigned int user_disabled:1;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
69 unsigned int group_disabled:1;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 };
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
72 extern struct quota_backend quota_backend_fs;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
73
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
74 static struct quota_root *fs_quota_alloc(void)
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
75 {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
76 struct fs_quota_root *root;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
77
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
78 root = i_new(struct fs_quota_root, 1);
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
79 root->uid = geteuid();
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
80 root->gid = getegid();
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
81
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
82 return &root->root;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
83 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
85 static int fs_quota_init(struct quota_root *_root, const char *args)
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
86 {
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
87 struct fs_quota_root *root = (struct fs_quota_root *)_root;
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
88 const char *const *tmp;
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
89
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
90 if (args == NULL)
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
91 return 0;
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
92
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
93 for (tmp = t_strsplit(args, ":"); *tmp != NULL; tmp++) {
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
94 if (strcmp(*tmp, "user") == 0)
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
95 root->group_disabled = TRUE;
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
96 else if (strcmp(*tmp, "group") == 0)
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
97 root->user_disabled = TRUE;
6203
d93098194ed4 inode_per_mail is now a parameter. We don't use it automatically.
Timo Sirainen <tss@iki.fi>
parents: 6202
diff changeset
98 else if (strcmp(*tmp, "inode_per_mail") == 0)
d93098194ed4 inode_per_mail is now a parameter. We don't use it automatically.
Timo Sirainen <tss@iki.fi>
parents: 6202
diff changeset
99 root->inode_per_mail = TRUE;
6874
1d0521b7151d Added noenforcing option to fs quota backend.
Timo Sirainen <tss@iki.fi>
parents: 6439
diff changeset
100 else if (strcmp(*tmp, "noenforcing") == 0)
1d0521b7151d Added noenforcing option to fs quota backend.
Timo Sirainen <tss@iki.fi>
parents: 6439
diff changeset
101 _root->no_enforcing = TRUE;
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
102 else if (strncmp(*tmp, "mount=", 6) == 0) {
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
103 i_free(root->storage_mount_path);
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
104 root->storage_mount_path = i_strdup(*tmp + 6);
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
105 } else {
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
106 i_error("fs quota: Invalid parameter: %s", *tmp);
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
107 return -1;
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
108 }
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
109 }
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
110 return 0;
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
111 }
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
112
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
113 static void fs_quota_mountpoint_free(struct fs_quota_mountpoint *mount)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 {
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
115 if (--mount->refcount > 0)
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
116 return;
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
117
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
118 #ifdef FS_QUOTA_SOLARIS
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
119 if (mount->fd != -1) {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
120 if (close(mount->fd) < 0)
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
121 i_error("close(%s) failed: %m", mount->path);
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
122 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
123 i_free(mount->path);
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
124 #endif
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
125
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
126 i_free(mount->device_path);
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
127 i_free(mount->mount_path);
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
128 i_free(mount->type);
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
129 i_free(mount);
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
130 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
131
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
132 static void fs_quota_deinit(struct quota_root *_root)
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
133 {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
134 struct fs_quota_root *root = (struct fs_quota_root *)_root;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
135
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
136 if (root->mount != NULL)
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
137 fs_quota_mountpoint_free(root->mount);
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
138 i_free(root->storage_mount_path);
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
139 i_free(root);
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
140 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
141
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
142 static struct fs_quota_mountpoint *fs_quota_mountpoint_get(const char *dir)
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
143 {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
144 struct fs_quota_mountpoint *mount;
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
145 struct mountpoint point;
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
146 int ret;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
148 ret = mountpoint_get(dir, default_pool, &point);
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
149 if (ret <= 0)
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
150 return NULL;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
152 mount = i_new(struct fs_quota_mountpoint, 1);
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
153 mount->refcount = 1;
4188
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
154 mount->device_path = point.device_path;
a3dc87033d2f Use mountpoint_get() instead of doing it ourself.
Timo Sirainen <tss@iki.fi>
parents: 4151
diff changeset
155 mount->mount_path = point.mount_path;
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
156 mount->type = point.type;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
157 return mount;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
160 #define QUOTA_ROOT_MATCH(root, mount) \
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
161 ((root)->root.backend.name == quota_backend_fs.name && \
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
162 ((root)->storage_mount_path == NULL || \
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
163 strcmp((root)->storage_mount_path, (mount)->mount_path) == 0))
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
164
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
165 static struct fs_quota_root *
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
166 fs_quota_root_find_mountpoint(struct quota *quota,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
167 const struct fs_quota_mountpoint *mount)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
169 struct quota_root *const *roots;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
170 struct fs_quota_root *empty = NULL;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
171 unsigned int i, count;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
172
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
173 roots = array_get(&quota->roots, &count);
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
174 for (i = 0; i < count; i++) {
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
175 struct fs_quota_root *root = (struct fs_quota_root *)roots[i];
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
176 if (QUOTA_ROOT_MATCH(root, mount)) {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
177 if (root->mount == NULL)
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
178 empty = root;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
179 else if (strcmp(root->mount->mount_path,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
180 mount->mount_path) == 0)
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
181 return root;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
182 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
183 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
184 return empty;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
185 }
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
186
6204
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
187 static void fs_quota_mount_init(struct fs_quota_root *root,
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
188 struct fs_quota_mountpoint *mount)
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
189 {
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
190 struct quota_root *const *roots;
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
191 unsigned int i, count;
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
192
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
193 #ifdef FS_QUOTA_SOLARIS
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
194 if (mount->path == NULL) {
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
195 mount->path = i_strconcat(mount->mount_path, "/quotas", NULL);
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
196 mount->fd = open(mount->path, O_RDONLY);
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
197 if (mount->fd == -1 && errno != ENOENT)
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
198 i_error("open(%s) failed: %m", mount->path);
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
199 }
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
200 #endif
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
201 root->mount = mount;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
202
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
203 /* if there are more unused quota roots, copy this mount to them */
6204
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
204 roots = array_get(&root->root.quota->roots, &count);
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
205 for (i = 0; i < count; i++) {
6202
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
206 struct fs_quota_root *root = (struct fs_quota_root *)roots[i];
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
207 if (QUOTA_ROOT_MATCH(root, mount) && root->mount == NULL) {
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
208 mount->refcount++;
1b01ff0180a5 Removed autocreation of quota roots. Added mount=<path> parameter to map
Timo Sirainen <tss@iki.fi>
parents: 6201
diff changeset
209 root->mount = mount;
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
210 }
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
211 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213
6204
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
214 static void fs_quota_add_missing_mounts(struct quota *quota)
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
215 {
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
216 struct fs_quota_mountpoint *mount;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
217 struct quota_root *const *roots;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
218 unsigned int i, count;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
219
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
220 roots = array_get(&quota->roots, &count);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
221 for (i = 0; i < count; i++) {
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
222 struct fs_quota_root *root = (struct fs_quota_root *)roots[i];
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
223
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
224 if (root->root.backend.name != quota_backend_fs.name ||
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
225 root->storage_mount_path == NULL || root->mount != NULL)
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
226 continue;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
227
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
228 mount = fs_quota_mountpoint_get(root->storage_mount_path);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
229 fs_quota_mount_init(root, mount);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
230 }
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
231 }
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
232
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
233 static void fs_quota_storage_added(struct quota *quota,
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
234 struct mail_storage *storage)
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
235 {
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
236 struct fs_quota_mountpoint *mount;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
237 struct fs_quota_root *root;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
238 const char *dir;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
239 bool is_file;
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
240
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
241 dir = mail_storage_get_mailbox_path(storage, "", &is_file);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
242 mount = fs_quota_mountpoint_get(dir);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
243 if (getenv("DEBUG") != NULL) {
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
244 i_info("fs quota add storage dir = %s", dir);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
245 i_info("fs quota block device = %s", mount->device_path);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
246 i_info("fs quota mount point = %s", mount->mount_path);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
247 }
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
248
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
249 root = fs_quota_root_find_mountpoint(quota, mount);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
250 if (root != NULL && root->mount == NULL)
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
251 fs_quota_mount_init(root, mount);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
252 else
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
253 fs_quota_mountpoint_free(mount);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
254
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
255 /* we would actually want to do this only once after all quota roots
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
256 are created, but there's no way to do this right now */
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
257 fs_quota_add_missing_mounts(quota);
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
258 }
8ab01c7b2927 Use quota roots with mount path even if we never see a storage for them.
Timo Sirainen <tss@iki.fi>
parents: 6203
diff changeset
259
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 static const char *const *
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
261 fs_quota_root_get_resources(struct quota_root *_root)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 {
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
263 struct fs_quota_root *root = (struct fs_quota_root *)_root;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
264 static const char *resources_kb[] = {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
265 QUOTA_NAME_STORAGE_KILOBYTES,
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
266 NULL
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
267 };
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
268 static const char *resources_kb_messages[] = {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
269 QUOTA_NAME_STORAGE_KILOBYTES,
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
270 QUOTA_NAME_MESSAGES,
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
271 NULL
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
272 };
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
274 return root->inode_per_mail ? resources_kb_messages : resources_kb;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276
6159
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
277 #ifdef HAVE_RQUOTA
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
278 /* retrieve user quota from a remote host */
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
279 static int do_rquota(struct fs_quota_root *root, bool bytes,
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
280 uint64_t *value_r, uint64_t *limit_r)
6159
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
281 {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
282 struct getquota_rslt result;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
283 struct getquota_args args;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
284 struct timeval timeout;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
285 enum clnt_stat call_status;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
286 CLIENT *cl;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
287 struct fs_quota_mountpoint *mount = root->mount;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
288 const char *host;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
289 char *path;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
290
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
291 path = strchr(mount->device_path, ':');
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
292 if (path == NULL) {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
293 i_error("quota-fs: %s is not a valid NFS device path",
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
294 mount->device_path);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
295 return -1;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
296 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
297
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
298 host = t_strdup_until(mount->device_path, path);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
299 path++;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
300
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
301 if (getenv("DEBUG") != NULL) {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
302 i_info("quota-fs: host=%s, path=%s, uid=%s",
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
303 host, path, dec2str(root->uid));
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
304 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
305
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
306 /* clnt_create() polls for a while to establish a connection */
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
307 cl = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp");
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
308 if (cl == NULL) {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
309 i_error("quota-fs: could not contact RPC service on %s",
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
310 host);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
311 return -1;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
312 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
313
6176
0f6d4f8dd587 Use authunix_create_default() with rquota. Patch by Steven Luo.
Timo Sirainen <tss@iki.fi>
parents: 6159
diff changeset
314 /* Establish some RPC credentials */
0f6d4f8dd587 Use authunix_create_default() with rquota. Patch by Steven Luo.
Timo Sirainen <tss@iki.fi>
parents: 6159
diff changeset
315 auth_destroy(cl->cl_auth);
0f6d4f8dd587 Use authunix_create_default() with rquota. Patch by Steven Luo.
Timo Sirainen <tss@iki.fi>
parents: 6159
diff changeset
316 cl->cl_auth = authunix_create_default();
0f6d4f8dd587 Use authunix_create_default() with rquota. Patch by Steven Luo.
Timo Sirainen <tss@iki.fi>
parents: 6159
diff changeset
317
6159
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
318 /* make the rquota call on the remote host */
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
319 args.gqa_pathp = path;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
320 args.gqa_uid = root->uid;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
321
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
322 timeout.tv_sec = RQUOTA_GETQUOTA_TIMEOUT_SECS;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
323 timeout.tv_usec = 0;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
324 call_status = clnt_call(cl, RQUOTAPROC_GETQUOTA,
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
325 (xdrproc_t)xdr_getquota_args, (char *)&args,
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
326 (xdrproc_t)xdr_getquota_rslt, (char *)&result,
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
327 timeout);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
328
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
329 /* the result has been deserialized, let the client go */
6176
0f6d4f8dd587 Use authunix_create_default() with rquota. Patch by Steven Luo.
Timo Sirainen <tss@iki.fi>
parents: 6159
diff changeset
330 auth_destroy(cl->cl_auth);
6159
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
331 clnt_destroy(cl);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
332
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
333 if (call_status != RPC_SUCCESS) {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
334 const char *rpc_error_msg = clnt_sperrno(call_status);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
335
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
336 i_error("quota-fs: remote rquota call failed: %s",
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
337 rpc_error_msg);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
338 return -1;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
339 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
340
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
341 switch (result.status) {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
342 case Q_OK: {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
343 /* convert the results from blocks to bytes */
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
344 rquota *rq = &result.getquota_rslt_u.gqr_rquota;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
345
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
346 if (rq->rq_active) {
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
347 if (bytes) {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
348 *value_r = (uint64_t)rq->rq_curblocks *
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
349 (uint64_t)rq->rq_bsize;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
350 *limit_r = (uint64_t)rq->rq_bsoftlimit *
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
351 (uint64_t)rq->rq_bsize;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
352 } else {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
353 *value_r = rq->rq_curfiles;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
354 *limit_r = rq->rq_fsoftlimit;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
355 }
6159
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
356 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
357 if (getenv("DEBUG") != NULL) {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
358 i_info("quota-fs: uid=%s, value=%llu, "
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
359 "limit=%llu, active=%d", dec2str(root->uid),
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
360 (unsigned long long)*value_r,
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
361 (unsigned long long)*limit_r, rq->rq_active);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
362 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
363 return 1;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
364 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
365 case Q_NOQUOTA:
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
366 if (getenv("DEBUG") != NULL) {
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
367 i_info("quota-fs: uid=%s, limit=unlimited",
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
368 dec2str(root->uid));
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
369 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
370 return 1;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
371 case Q_EPERM:
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
372 i_error("quota-fs: permission denied to rquota service");
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
373 return -1;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
374 default:
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
375 i_error("quota-fs: unrecognized status code (%d) "
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
376 "from rquota service", result.status);
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
377 return -1;
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
378 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
379 }
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
380 #endif
078d9dde99c8 Support for rquota with NFS mounts. Patch by HTK NetCommunication Oy.
Timo Sirainen <tss@iki.fi>
parents: 5704
diff changeset
381
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
382 #if defined(FS_QUOTA_LINUX) || defined(FS_QUOTA_BSDAIX)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
383 static void fs_quota_root_disable(struct fs_quota_root *root, bool group)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
384 {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
385 if (group)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
386 root->group_disabled = TRUE;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
387 else
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
388 root->user_disabled = TRUE;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
389 }
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
390 #endif
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
391
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
392 #ifdef FS_QUOTA_LINUX
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 static int
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
394 fs_quota_get_linux(struct fs_quota_root *root, bool group, bool bytes,
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
395 uint64_t *value_r, uint64_t *limit_r)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 {
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 struct dqblk dqblk;
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
398 int type, id;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
399
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
400 type = group ? GRPQUOTA : USRQUOTA;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
401 id = group ? root->gid : root->uid;
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402
4565
a54558861acc Check for XFS quota also from xfs/xqm.h
Timo Sirainen <tss@iki.fi>
parents: 4552
diff changeset
403 #ifdef HAVE_XFS_QUOTA
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
404 if (strcmp(root->mount->type, "xfs") == 0) {
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
405 struct fs_disk_quota xdqblk;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
406
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
407 if (quotactl(QCMD(Q_XGETQUOTA, type),
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
408 root->mount->device_path,
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
409 id, (caddr_t)&xdqblk) < 0) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
410 if (errno == ESRCH) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
411 fs_quota_root_disable(root, group);
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
412 return 0;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
413 }
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
414 i_error("%d quotactl(Q_XGETQUOTA, %s) failed: %m",
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
415 errno, root->mount->device_path);
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
416 return -1;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
417 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
418
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
419 if (bytes) {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
420 /* values always returned in 512 byte blocks */
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
421 *value_r = xdqblk.d_bcount * 512;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
422 *limit_r = xdqblk.d_blk_softlimit * 512;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
423 } else {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
424 *value_r = xdqblk.d_icount;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
425 *limit_r = xdqblk.d_ino_softlimit;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
426 }
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
427 } else
4192
26e028337e1e quotactl() parameters were backwards for BSDs and AIX.
Timo Sirainen <tss@iki.fi>
parents: 4188
diff changeset
428 #endif
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
429 {
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
430 /* ext2, ext3 */
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
431 if (quotactl(QCMD(Q_GETQUOTA, type),
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
432 root->mount->device_path,
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
433 id, (caddr_t)&dqblk) < 0) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
434 if (errno == ESRCH) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
435 fs_quota_root_disable(root, group);
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
436 return 0;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
437 }
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
438 i_error("quotactl(Q_GETQUOTA, %s) failed: %m",
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
439 root->mount->device_path);
4530
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
440 if (errno == EINVAL) {
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
441 i_error("Dovecot was compiled with Linux quota "
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
442 "v%d support, try changing it "
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
443 "(--with-linux-quota configure option)",
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
444 _LINUX_QUOTA_VERSION);
f598896bb40a Added --with-linux-quota configure option to specify which Linux quota
Timo Sirainen <tss@iki.fi>
parents: 4514
diff changeset
445 }
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
446 return -1;
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
447 }
4448
cf334cc732e7 Attempting to fix quota block calculations to be correct.
Timo Sirainen <tss@iki.fi>
parents: 4387
diff changeset
448
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
449 if (bytes) {
5174
a911767f89c0 Linux quota v1 apparently returns current quota in kilobytes, not bytes as
Timo Sirainen <tss@iki.fi>
parents: 4844
diff changeset
450 #if _LINUX_QUOTA_VERSION == 1
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
451 *value_r = dqblk.dqb_curblocks * 1024;
5174
a911767f89c0 Linux quota v1 apparently returns current quota in kilobytes, not bytes as
Timo Sirainen <tss@iki.fi>
parents: 4844
diff changeset
452 #else
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
453 *value_r = dqblk.dqb_curblocks;
5174
a911767f89c0 Linux quota v1 apparently returns current quota in kilobytes, not bytes as
Timo Sirainen <tss@iki.fi>
parents: 4844
diff changeset
454 #endif
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
455 *limit_r = dqblk.dqb_bsoftlimit * 1024;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
456 } else {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
457 *value_r = dqblk.dqb_curinodes;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
458 *value_r = dqblk.dqb_isoftlimit;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
459 }
4387
670dd15edbf3 Added support for XFS disk quotas. Patch by Pawel Jarosz
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
460 }
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
461 return 1;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
462 }
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
463 #endif
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
464
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
465 #ifdef FS_QUOTA_BSDAIX
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
466 static int
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
467 fs_quota_get_bsdaix(struct fs_quota_root *root, bool group, bool bytes,
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
468 uint64_t *value_r, uint64_t *limit_r)
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
469 {
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
470 struct dqblk dqblk;
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
471 int type, id;
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
472
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
473 type = group ? GRPQUOTA : USRQUOTA;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
474 id = group ? root->gid : root->uid;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
475
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
476 if (quotactl(root->mount->mount_path, QCMD(Q_GETQUOTA, type),
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
477 id, (void *)&dqblk) < 0) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
478 if (errno == ESRCH) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
479 fs_quota_root_disable(root, group);
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
480 return 0;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
481 }
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
482 i_error("quotactl(Q_GETQUOTA, %s) failed: %m",
4468
ce47b2f84cdb BSD's quotactl() wants a file path, not a device path.
Timo Sirainen <tss@iki.fi>
parents: 4448
diff changeset
483 root->mount->mount_path);
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484 return -1;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 }
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
486 if (bytes) {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
487 *value_r = (uint64_t)dqblk.dqb_curblocks * DEV_BSIZE;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
488 *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * DEV_BSIZE;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
489 } else {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
490 *value_r = dqblk.dqb_curinodes;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
491 *value_r = dqblk.dqb_isoftlimit;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
492 }
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
493 return 1;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
494 }
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
495 #endif
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
496
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
497 #ifdef FS_QUOTA_SOLARIS
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
498 static int
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
499 fs_quota_get_solaris(struct fs_quota_root *root, bool bytes,
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
500 uint64_t *value_r, uint64_t *limit_r)
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
501 {
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
502 struct dqblk dqblk;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
503 struct quotctl ctl;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
504
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
505 if (root->mount->fd == -1)
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
506 return 0;
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
507
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
508 ctl.op = Q_GETQUOTA;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
509 ctl.uid = root->uid;
4066
30ad1815cf1e Compiler warning fix
Timo Sirainen <tss@iki.fi>
parents: 4063
diff changeset
510 ctl.addr = (caddr_t)&dqblk;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
511 if (ioctl(root->mount->fd, Q_QUOTACTL, &ctl) < 0) {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
512 i_error("ioctl(%s, Q_QUOTACTL) failed: %m", root->mount->path);
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
513 return -1;
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
514 }
6184
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
515 if (bytes) {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
516 *value_r = (uint64_t)dqblk.dqb_curblocks * DEV_BSIZE;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
517 *limit_r = (uint64_t)dqblk.dqb_bsoftlimit * DEV_BSIZE;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
518 } else {
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
519 *value_r = dqblk.dqb_curfiles;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
520 *value_r = dqblk.dqb_fsoftlimit;
cacb72a465c1 With maildir and cydir formats return inode limit as message count limit.
Timo Sirainen <tss@iki.fi>
parents: 6177
diff changeset
521 }
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
522 return 1;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
523 }
4063
f60237ad2edd Support Solaris's ioctl(Q_QUOTACTL).
Timo Sirainen <tss@iki.fi>
parents: 4060
diff changeset
524 #endif
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
525
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
526 static int
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
527 fs_quota_get_one_resource(struct fs_quota_root *root, bool group, bool bytes,
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
528 uint64_t *value_r, uint64_t *limit_r)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
529 {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
530 if (group) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
531 if (root->group_disabled)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
532 return 0;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
533 } else {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
534 if (root->user_disabled)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
535 return 0;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
536 }
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
537 #ifdef FS_QUOTA_LINUX
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
538 return fs_quota_get_linux(root, group, bytes, value_r, limit_r);
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
539 #elif defined (FS_QUOTA_BSDAIX)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
540 return fs_quota_get_bsdaix(root, group, bytes, value_r, limit_r);
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
541 #else
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
542 if (group) {
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
543 /* not supported */
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
544 return 0;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
545 }
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
546 return fs_quota_get_solaris(root, bytes, value_r, limit_r);
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
547 #endif
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
548 }
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
549
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
550 static int
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
551 fs_quota_get_resource(struct quota_root *_root, const char *name,
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
552 uint64_t *value_r, uint64_t *limit_r)
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
553 {
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
554 struct fs_quota_root *root = (struct fs_quota_root *)_root;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
555 bool bytes;
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
556 int ret;
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
557
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
558 *value_r = 0;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
559 *limit_r = 0;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
560
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
561 if (root->mount == NULL ||
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
562 (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0 &&
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
563 strcasecmp(name, QUOTA_NAME_MESSAGES) != 0))
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
564 return 0;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
565 bytes = strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) == 0;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
566
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
567 #ifdef HAVE_RQUOTA
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
568 if (strcmp(root->mount->type, "nfs") == 0) {
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
569 int ret;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
570
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6874
diff changeset
571 T_FRAME(
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6874
diff changeset
572 ret = do_rquota(root, bytes, value_r, limit_r);
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6874
diff changeset
573 );
6185
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
574 return ret;
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
575 }
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
576 #endif
685a6f165193 Code cleanups.
Timo Sirainen <tss@iki.fi>
parents: 6184
diff changeset
577
6186
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
578 ret = fs_quota_get_one_resource(root, FALSE, bytes,
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
579 value_r, limit_r);
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
580 if (ret != 0)
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
581 return ret;
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
582
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
583 /* fallback to group quota */
9a3a7ad297cf Added support for group quotas.
Timo Sirainen <tss@iki.fi>
parents: 6185
diff changeset
584 return fs_quota_get_one_resource(root, TRUE, bytes, value_r, limit_r);
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
586
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
587 static int
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6204
diff changeset
588 fs_quota_update(struct quota_root *root ATTR_UNUSED,
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6204
diff changeset
589 struct quota_transaction_context *ctx ATTR_UNUSED)
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
590 {
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
591 return 0;
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
592 }
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
593
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
594 struct quota_backend quota_backend_fs = {
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
595 "fs",
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
596
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
597 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
598 fs_quota_alloc,
6201
4a8a19fea50d Added user and group parameters which allow forcing user/group quota
Timo Sirainen <tss@iki.fi>
parents: 6186
diff changeset
599 fs_quota_init,
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
600 fs_quota_deinit,
5704
4bf8438b497f Allow backend-specific quota rules with backend=<string>.
Timo Sirainen <tss@iki.fi>
parents: 5174
diff changeset
601 NULL,
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
602
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
603 fs_quota_storage_added,
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
604
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
605 fs_quota_root_get_resources,
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
606 fs_quota_get_resource,
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4468
diff changeset
607 fs_quota_update
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4066
diff changeset
608 }
3751
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
609 };
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
610
768770a01733 quotactl() quota checking support
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
611 #endif