16
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
/* $Id: opts.c,v 1.59 2008/03/31 07:45:32 sfjro Exp $ */
22
* $Id: opts.c,v 1.61 2008/04/13 23:44:07 sfjro Exp $
21
25
#include <linux/types.h> /* a distribution requires */
22
26
#include <linux/parser.h>
25
void au_opts_flags_def(struct au_opts_flags *flags)
27
// self-check at build time.
28
flags->f_wbr_create = AuWbrCreate_Last - 1;
30
flags->f_xino = AuXino_XINO;
31
flags->f_trunc_xino = 0;
32
flags->f_dirperm1 = 0;
34
flags->f_udba = AuUdba_REVAL;
37
flags->f_warn_perm = 1;
38
flags->f_coo = AuCoo_NONE;
39
flags->f_always_diropq = 0;
42
flags->f_wbr_copyup = AuWbrCopyup_TDP;
43
flags->f_wbr_create = AuWbrCreate_TDP;
45
#ifdef CONFIG_AUFS_COMPAT
46
flags->f_always_diropq = 1;
48
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
53
29
/* ---------------------------------------------------------------------- */
248
224
/* ---------------------------------------------------------------------- */
250
226
static match_table_t udbalevel = {
251
{AuUdba_REVAL, "reval"},
227
{AuOpt_UDBA_REVAL, "reval"},
252
228
#ifdef CONFIG_AUFS_HINOTIFY
253
{AuUdba_INOTIFY, "inotify"},
229
{AuOpt_UDBA_INOTIFY, "inotify"},
255
{AuUdba_NONE, "none"},
231
{AuOpt_UDBA_NONE, "none"},
1021
997
struct au_opts *opts)
1024
struct aufs_sbinfo *sbinfo;
1025
struct au_opts_flags *given;
1000
struct au_sbinfo *sbinfo;
1026
1001
struct au_opt_wbr_create *create;
1028
1003
AuTraceEnter();
1030
1005
err = 1; /* handled */
1032
given = &opts->given;
1006
sbinfo = au_sbi(sb);
1033
1007
switch (opt->type) {
1035
AuFlagSet(sbinfo, f_udba, opt->udba);
1009
sbinfo->si_mntflags &= ~AuOptMask_UDBA;
1010
sbinfo->si_mntflags |= opt->udba;
1011
opts->given_udba |= opt->udba;
1039
1014
case Opt_plink:
1040
AuFlagSet(sbinfo, f_plink, 1);
1015
au_opt_set(sbinfo->si_mntflags, PLINK);
1043
1017
case Opt_noplink:
1044
if (AuFlag(sbinfo, f_plink))
1046
AuFlagSet(sbinfo, f_plink, 0);
1018
if (au_opt_test(sbinfo->si_mntflags, PLINK))
1020
au_opt_clr(sbinfo->si_mntflags, PLINK);
1049
1022
case Opt_list_plink:
1050
if (AuFlag(sbinfo, f_plink))
1023
if (au_opt_test(sbinfo->si_mntflags, PLINK))
1053
1026
case Opt_clean_plink:
1054
if (AuFlag(sbinfo, f_plink))
1027
if (au_opt_test(sbinfo->si_mntflags, PLINK))
1058
1031
case Opt_diropq_a:
1059
AuFlagSet(sbinfo, f_always_diropq, 1);
1060
given->f_always_diropq = 1;
1032
au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
1062
1034
case Opt_diropq_w:
1063
AuFlagSet(sbinfo, f_always_diropq, 0);
1064
given->f_always_diropq = 1;
1035
au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
1068
AuFlagSet(sbinfo, f_dlgt, 1);
1039
au_opt_set(sbinfo->si_mntflags, DLGT);
1071
1041
case Opt_nodlgt:
1072
AuFlagSet(sbinfo, f_dlgt, 0);
1042
au_opt_clr(sbinfo->si_mntflags, DLGT);
1076
1045
case Opt_warn_perm:
1077
AuFlagSet(sbinfo, f_warn_perm, 1);
1078
given->f_warn_perm = 1;
1046
au_opt_set(sbinfo->si_mntflags, WARN_PERM);
1080
1048
case Opt_nowarn_perm:
1081
AuFlagSet(sbinfo, f_warn_perm, 0);
1082
given->f_warn_perm = 1;
1049
au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
1085
1052
case Opt_refrof:
1086
AuFlagSet(sbinfo, f_refrof, 1);
1087
given->f_refrof = 1;
1053
au_opt_set(sbinfo->si_mntflags, REFROF);
1089
1055
case Opt_norefrof:
1090
//coo_set(sb, AuFlag_COO_LEAF);
1091
AuFlagSet(sbinfo, f_refrof, 0);
1092
given->f_refrof = 1;
1056
//au_opt_set(sbinfo->si_mntflags, COO_LEAF);
1057
au_opt_clr(sbinfo->si_mntflags, REFROF);
1095
1060
case Opt_verbose:
1096
AuFlagSet(sbinfo, f_verbose, 1);
1097
given->f_verbose = 1;
1061
au_opt_set(sbinfo->si_mntflags, VERBOSE);
1099
1063
case Opt_noverbose:
1100
AuFlagSet(sbinfo, f_verbose, 0);
1101
given->f_verbose = 1;
1064
au_opt_clr(sbinfo->si_mntflags, VERBOSE);
1104
1067
case Opt_wbr_create:
1127
1090
if (sbinfo->si_wbr_create_ops->init)
1128
1091
sbinfo->si_wbr_create_ops->init(sb); /* ignore */
1129
given->f_wbr_create = 1;
1131
1093
case Opt_wbr_copyup:
1132
AuFlagSet(sbinfo, f_wbr_copyup, opt->wbr_copyup);
1094
sbinfo->si_wbr_copyup = opt->wbr_copyup;
1133
1095
sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
1134
given->f_wbr_copyup = 1;
1138
AuFlagSet(sbinfo, f_coo, opt->coo);
1099
sbinfo->si_mntflags &= ~AuOptMask_COO;
1100
sbinfo->si_mntflags |= opt->coo;
1142
1103
case Opt_dirwh:
1150
1111
case Opt_trunc_xino:
1151
AuFlagSet(sbinfo, f_trunc_xino, 1);
1152
given->f_trunc_xino = 1;
1112
au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
1154
1114
case Opt_notrunc_xino:
1155
AuFlagSet(sbinfo, f_trunc_xino, 0);
1156
given->f_trunc_xino = 1;
1115
au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
1159
1118
case Opt_dirperm1:
1160
AuFlagSet(sbinfo, f_dirperm1, 1);
1161
given->f_dirperm1 = 1;
1119
au_opt_set(sbinfo->si_mntflags, DIRPERM1);
1163
1121
case Opt_nodirperm1:
1164
AuFlagSet(sbinfo, f_dirperm1, 0);
1165
given->f_dirperm1 = 1;
1122
au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
1169
AuFlagSet(sbinfo, f_shwh, 1);
1126
au_opt_set(sbinfo->si_mntflags, SHWH);
1172
1128
case Opt_noshwh:
1173
AuFlagSet(sbinfo, f_shwh, 0);
1129
au_opt_clr(sbinfo->si_mntflags, SHWH);
1177
1132
case Opt_trunc_xino_path:
1178
1133
case Opt_itrunc_xino:
1179
err = xino_trunc(sb, opt->xino_itrunc.bindex);
1134
err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
1221
1176
opt->add.bindex = 0;
1224
err = br_add(sb, &opt->add,
1225
au_ftest_opts(opts->flags, REMOUNT));
1179
err = au_br_add(sb, &opt->add,
1180
au_ftest_opts(opts->flags, REMOUNT));
1228
1183
au_fset_opts(opts->flags, REFRESH_DIR);
1229
if (unlikely(br_whable(opt->add.perm)))
1184
if (unlikely(au_br_whable(opt->add.perm)))
1230
1185
au_fset_opts(opts->flags, REFRESH_NONDIR);
1236
err = br_del(sb, &opt->del,
1237
au_ftest_opts(opts->flags, REMOUNT));
1191
err = au_br_del(sb, &opt->del,
1192
au_ftest_opts(opts->flags, REMOUNT));
1240
1195
au_fset_opts(opts->flags, TRUNC_XIB);
1289
static int verify_opts(struct super_block *sb, struct au_opts_flags *pending,
1245
static int verify_opts(struct super_block *sb, unsigned int pending,
1293
1249
aufs_bindex_t bindex, bend;
1294
struct aufs_branch *br;
1250
struct au_branch *br;
1295
1251
struct dentry *root;
1296
1252
struct inode *dir;
1297
1253
unsigned int do_plink;
1298
struct aufs_sbinfo *sbinfo;
1254
unsigned int mnt_flags;
1300
1256
AuTraceEnter();
1257
mnt_flags = au_mntflags(sb);
1258
AuDebugOn(!(mnt_flags & AuOptMask_COO));
1259
AuDebugOn(!(mnt_flags & AuOptMask_UDBA));
1302
1261
if (!(sb->s_flags & MS_RDONLY)) {
1303
if (unlikely(!br_writable(sbr_perm(sb, 0))))
1262
if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
1304
1263
AuWarn("first branch should be rw\n");
1305
if (unlikely(au_flag_test_shwh(sb)))
1264
if (unlikely(au_opt_test(mnt_flags, SHWH)))
1306
1265
AuWarn("shwh should be used with ro\n");
1310
if (unlikely((au_flag_test_udba_inotify(sb)
1311
|| pending->f_udba == AuUdba_INOTIFY)
1312
&& AuFlag(sbinfo, f_xino) == AuXino_NONE))
1268
if (unlikely(au_opt_test(mnt_flags | pending, UDBA_INOTIFY)
1269
&& !au_opt_test(mnt_flags, XINO)))
1313
1270
AuWarn("udba=inotify requires xino\n");
1316
1273
root = sb->s_root;
1317
1274
dir = sb->s_root->d_inode;
1318
do_plink = AuFlag(sbinfo, f_plink);
1275
do_plink = !!au_opt_test(mnt_flags, PLINK);
1276
bend = au_sbend(sb);
1320
1277
for (bindex = 0; !err && bindex <= bend; bindex++) {
1321
1278
struct inode *h_dir;
1325
1282
h_dir = au_h_iptr_i(dir, bindex);
1326
br = stobr(sb, bindex);
1283
br = au_sbr(sb, bindex);
1327
1284
br_wh_read_lock(br);
1328
1285
switch (br->br_perm) {
1364
hdir_lock(h_dir, dir, bindex);
1321
au_hdir_lock(h_dir, dir, bindex);
1365
1322
br_wh_write_lock(br);
1366
err = init_wh(au_h_dptr_i(root, bindex), br,
1367
au_nfsmnt(sb, bindex), sb);
1323
err = au_wh_init(au_h_dptr_i(root, bindex), br,
1324
au_nfsmnt(sb, bindex), sb);
1368
1325
br_wh_write_unlock(br);
1369
hdir_unlock(h_dir, dir, bindex);
1326
au_hdir_unlock(h_dir, dir, bindex);
1372
1329
AuTraceErr(err);
1402
1359
/* disable xino, hinotify, dlgt temporary */
1404
tmp = sbinfo->au_si_flags;
1405
AuFlagSet(sbinfo, f_xino, AuXino_NONE);
1406
AuFlagSet(sbinfo, f_dlgt, 0);
1407
AuFlagSet(sbinfo, f_udba, AuUdba_REVAL);
1360
sbinfo = au_sbi(sb);
1361
tmp = sbinfo->si_mntflags;
1362
au_opt_clr(sbinfo->si_mntflags, XINO);
1363
au_opt_clr(sbinfo->si_mntflags, DLGT);
1364
au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
1409
1366
opt = opts->opt;
1410
1367
while (err >= 0 && opt->type != Opt_tail)
1414
1371
else if (unlikely(err < 0))
1374
bend = au_sbend(sb);
1418
1375
if (unlikely(bend < 0)) {
1420
1377
AuErr("no branches\n");
1424
AuFlagSet(sbinfo, f_xino, tmp.f_xino);
1381
if (au_opt_test(tmp, XINO))
1382
au_opt_set(sbinfo->si_mntflags, XINO);
1425
1383
opt = opts->opt;
1426
1384
while (!err && opt->type != Opt_tail)
1427
1385
err = au_opt_xino(sb, opt++, &opt_xino, opts);
1431
1389
//todo: test this error case.
1432
err = verify_opts(sb, &tmp, /*remount*/0);
1390
err = verify_opts(sb, tmp, /*remount*/0);
1433
1391
if (unlikely(err))
1436
1394
/* enable xino */
1437
if (tmp.f_xino != AuXino_NONE && !opt_xino) {
1395
if (au_opt_test(tmp, XINO) && !opt_xino) {
1438
1396
struct au_opt_xino xino;
1440
xino.file = xino_def(sb);
1398
xino.file = au_xino_def(sb);
1441
1399
err = PTR_ERR(xino.file);
1442
1400
if (IS_ERR(xino.file))
1445
err = xino_set(sb, &xino, /*remount*/0);
1403
err = au_xino_set(sb, &xino, /*remount*/0);
1446
1404
fput(xino.file);
1447
1405
if (unlikely(err))
1451
1409
/* restore hinotify */
1452
AuFlagSet(sbinfo, f_udba, tmp.f_udba);
1453
if (tmp.f_udba == AuUdba_INOTIFY)
1410
sbinfo->si_mntflags &= ~AuOptMask_UDBA;
1411
sbinfo->si_mntflags |= (tmp & AuOptMask_UDBA);
1412
if (au_opt_test(tmp, UDBA_INOTIFY))
1454
1413
au_reset_hinotify(dir, au_hi_flags(dir, 1) & ~AuHi_XINO);
1456
1415
/* restore dlgt */
1457
AuFlagSet(sbinfo, f_dlgt, tmp.f_dlgt);
1416
if (au_opt_test_dlgt(tmp))
1417
au_opt_set(sbinfo->si_mntflags, DLGT);
1460
1420
AuTraceErr(err);
1468
1428
struct au_opt_xino *opt_xino;
1469
1429
struct au_opt *opt;
1470
1430
unsigned int dlgt;
1471
struct aufs_sbinfo *sbinfo;
1431
struct au_sbinfo *sbinfo;
1473
1433
AuTraceEnter();
1474
1434
SiMustWriteLock(sb);
1475
1435
DiMustWriteLock(sb->s_root);
1476
1436
dir = sb->s_root->d_inode;
1477
1437
IiMustWriteLock(dir);
1478
//AuDebugOn(au_flag_test_udba_inotify(sb));
1438
sbinfo = au_sbi(sb);
1439
//AuDebugOn(au_opt_test(sbifno->si_mntflags, UDBA_INOTIFY));
1482
dlgt = au_need_dlgt(sb);
1442
dlgt = !!au_opt_test_dlgt(sbinfo->si_mntflags);
1483
1443
opt_xino = NULL;
1484
1444
opt = opts->opt;
1485
1445
while (err >= 0 && opt->type != Opt_tail) {
1486
1446
err = au_opt_simple(sb, opt, opts);
1488
1448
/* disable it temporary */
1489
dlgt = au_need_dlgt(sb);
1490
AuFlagSet(sbinfo, f_dlgt, 0);
1449
dlgt = !!au_opt_test_dlgt(sbinfo->si_mntflags);
1450
au_opt_clr(sbinfo->si_mntflags, DLGT);
1493
1453
err = au_opt_br(sb, opt, opts);
1505
1466
/* go on even err */
1507
1468
//todo: test this error case.
1508
AuFlagSet(sbinfo, f_dlgt, 0);
1509
rerr = verify_opts(sb, &sbinfo->au_si_flags, /*remount*/1);
1510
AuFlagSet(sbinfo, f_dlgt, dlgt);
1469
au_opt_clr(sbinfo->si_mntflags, DLGT);
1470
rerr = verify_opts(sb, sbinfo->si_mntflags, /*remount*/1);
1472
au_opt_set(sbinfo->si_mntflags, DLGT);
1511
1473
if (unlikely(rerr && !err))
1514
1476
if (unlikely(au_ftest_opts(opts->flags, TRUNC_XIB))) {
1515
rerr = xib_trunc(sb);
1477
rerr = au_xib_trunc(sb);
1516
1478
if (unlikely(rerr && !err))
1520
1482
/* they are handled by the caller */
1521
1483
if (!au_ftest_opts(opts->flags, REFRESH_DIR)
1522
&& (opts->given.f_udba || AuFlag(sbinfo, f_xino) != AuXino_NONE))
1484
&& (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
1523
1485
au_fset_opts(opts->flags, REFRESH_DIR);
1525
1487
LKTRTrace("status 0x%x\n", opts->flags);