forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
super.c
2295 lines (2056 loc) · 63.5 KB
/
super.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
*
* Trivial changes by Alan Cox to add the LFS fixes
*
* Trivial Changes:
* Rights granted to Hans Reiser to redistribute under other terms providing
* he accepts all liability including but not limited to patent, fitness
* for purpose, and direct or indirect claims arising from failure to perform.
*
* NO WARRANTY
*/
#include <linux/module.h>
#include <linux/vmalloc.h>
#include <linux/time.h>
#include <asm/uaccess.h>
#include <linux/reiserfs_fs.h>
#include <linux/reiserfs_acl.h>
#include <linux/reiserfs_xattr.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/exportfs.h>
#include <linux/quotaops.h>
#include <linux/vfs.h>
#include <linux/mnt_namespace.h>
#include <linux/mount.h>
#include <linux/namei.h>
struct file_system_type reiserfs_fs_type;
static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
int is_reiserfs_3_5(struct reiserfs_super_block *rs)
{
return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
strlen(reiserfs_3_5_magic_string));
}
int is_reiserfs_3_6(struct reiserfs_super_block *rs)
{
return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
strlen(reiserfs_3_6_magic_string));
}
int is_reiserfs_jr(struct reiserfs_super_block *rs)
{
return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
strlen(reiserfs_jr_magic_string));
}
static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
{
return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
is_reiserfs_jr(rs));
}
static int reiserfs_remount(struct super_block *s, int *flags, char *data);
static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
static int reiserfs_sync_fs(struct super_block *s, int wait)
{
if (!(s->s_flags & MS_RDONLY)) {
struct reiserfs_transaction_handle th;
reiserfs_write_lock(s);
if (!journal_begin(&th, s, 1))
if (!journal_end_sync(&th, s, 1))
reiserfs_flush_old_commits(s);
s->s_dirt = 0; /* Even if it's not true.
* We'll loop forever in sync_supers otherwise */
reiserfs_write_unlock(s);
} else {
s->s_dirt = 0;
}
return 0;
}
static void reiserfs_write_super(struct super_block *s)
{
reiserfs_sync_fs(s, 1);
}
static void reiserfs_write_super_lockfs(struct super_block *s)
{
struct reiserfs_transaction_handle th;
reiserfs_write_lock(s);
if (!(s->s_flags & MS_RDONLY)) {
int err = journal_begin(&th, s, 1);
if (err) {
reiserfs_block_writes(&th);
} else {
reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
1);
journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
reiserfs_block_writes(&th);
journal_end_sync(&th, s, 1);
}
}
s->s_dirt = 0;
reiserfs_write_unlock(s);
}
static void reiserfs_unlockfs(struct super_block *s)
{
reiserfs_allow_writes(s);
}
extern const struct in_core_key MAX_IN_CORE_KEY;
/* this is used to delete "save link" when there are no items of a
file it points to. It can either happen if unlink is completed but
"save unlink" removal, or if file has both unlink and truncate
pending and as unlink completes first (because key of "save link"
protecting unlink is bigger that a key lf "save link" which
protects truncate), so there left no items to make truncate
completion on */
static int remove_save_link_only(struct super_block *s,
struct reiserfs_key *key, int oid_free)
{
struct reiserfs_transaction_handle th;
int err;
/* we are going to do one balancing */
err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
if (err)
return err;
reiserfs_delete_solid_item(&th, NULL, key);
if (oid_free)
/* removals are protected by direct items */
reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
}
#ifdef CONFIG_QUOTA
static int reiserfs_quota_on_mount(struct super_block *, int);
#endif
/* look for uncompleted unlinks and truncates and complete them */
static int finish_unfinished(struct super_block *s)
{
INITIALIZE_PATH(path);
struct cpu_key max_cpu_key, obj_key;
struct reiserfs_key save_link_key, last_inode_key;
int retval = 0;
struct item_head *ih;
struct buffer_head *bh;
int item_pos;
char *item;
int done;
struct inode *inode;
int truncate;
#ifdef CONFIG_QUOTA
int i;
int ms_active_set;
#endif
/* compose key to look for "save" links */
max_cpu_key.version = KEY_FORMAT_3_5;
max_cpu_key.on_disk_key.k_dir_id = ~0U;
max_cpu_key.on_disk_key.k_objectid = ~0U;
set_cpu_key_k_offset(&max_cpu_key, ~0U);
max_cpu_key.key_length = 3;
memset(&last_inode_key, 0, sizeof(last_inode_key));
#ifdef CONFIG_QUOTA
/* Needed for iput() to work correctly and not trash data */
if (s->s_flags & MS_ACTIVE) {
ms_active_set = 0;
} else {
ms_active_set = 1;
s->s_flags |= MS_ACTIVE;
}
/* Turn on quotas so that they are updated correctly */
for (i = 0; i < MAXQUOTAS; i++) {
if (REISERFS_SB(s)->s_qf_names[i]) {
int ret = reiserfs_quota_on_mount(s, i);
if (ret < 0)
reiserfs_warning(s,
"reiserfs: cannot turn on journaled quota: error %d",
ret);
}
}
#endif
done = 0;
REISERFS_SB(s)->s_is_unlinked_ok = 1;
while (!retval) {
retval = search_item(s, &max_cpu_key, &path);
if (retval != ITEM_NOT_FOUND) {
reiserfs_warning(s,
"vs-2140: finish_unfinished: search_by_key returned %d",
retval);
break;
}
bh = get_last_bh(&path);
item_pos = get_item_pos(&path);
if (item_pos != B_NR_ITEMS(bh)) {
reiserfs_warning(s,
"vs-2060: finish_unfinished: wrong position found");
break;
}
item_pos--;
ih = B_N_PITEM_HEAD(bh, item_pos);
if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
/* there are no "save" links anymore */
break;
save_link_key = ih->ih_key;
if (is_indirect_le_ih(ih))
truncate = 1;
else
truncate = 0;
/* reiserfs_iget needs k_dirid and k_objectid only */
item = B_I_PITEM(bh, ih);
obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
obj_key.on_disk_key.k_objectid =
le32_to_cpu(ih->ih_key.k_objectid);
obj_key.on_disk_key.k_offset = 0;
obj_key.on_disk_key.k_type = 0;
pathrelse(&path);
inode = reiserfs_iget(s, &obj_key);
if (!inode) {
/* the unlink almost completed, it just did not manage to remove
"save" link and release objectid */
reiserfs_warning(s,
"vs-2180: finish_unfinished: iget failed for %K",
&obj_key);
retval = remove_save_link_only(s, &save_link_key, 1);
continue;
}
if (!truncate && inode->i_nlink) {
/* file is not unlinked */
reiserfs_warning(s,
"vs-2185: finish_unfinished: file %K is not unlinked",
&obj_key);
retval = remove_save_link_only(s, &save_link_key, 0);
continue;
}
DQUOT_INIT(inode);
if (truncate && S_ISDIR(inode->i_mode)) {
/* We got a truncate request for a dir which is impossible.
The only imaginable way is to execute unfinished truncate request
then boot into old kernel, remove the file and create dir with
the same key. */
reiserfs_warning(s,
"green-2101: impossible truncate on a directory %k. Please report",
INODE_PKEY(inode));
retval = remove_save_link_only(s, &save_link_key, 0);
truncate = 0;
iput(inode);
continue;
}
if (truncate) {
REISERFS_I(inode)->i_flags |=
i_link_saved_truncate_mask;
/* not completed truncate found. New size was committed together
with "save" link */
reiserfs_info(s, "Truncating %k to %Ld ..",
INODE_PKEY(inode), inode->i_size);
reiserfs_truncate_file(inode,
0
/*don't update modification time */
);
retval = remove_save_link(inode, truncate);
} else {
REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
/* not completed unlink (rmdir) found */
reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
if (memcmp(&last_inode_key, INODE_PKEY(inode),
sizeof(last_inode_key))){
last_inode_key = *INODE_PKEY(inode);
/* removal gets completed in iput */
retval = 0;
} else {
reiserfs_warning(s, "Dead loop in "
"finish_unfinished detected, "
"just remove save link\n");
retval = remove_save_link_only(s,
&save_link_key, 0);
}
}
iput(inode);
printk("done\n");
done++;
}
REISERFS_SB(s)->s_is_unlinked_ok = 0;
#ifdef CONFIG_QUOTA
/* Turn quotas off */
for (i = 0; i < MAXQUOTAS; i++) {
if (sb_dqopt(s)->files[i])
vfs_quota_off(s, i, 0);
}
if (ms_active_set)
/* Restore the flag back */
s->s_flags &= ~MS_ACTIVE;
#endif
pathrelse(&path);
if (done)
reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
"Completed\n", done);
return retval;
}
/* to protect file being unlinked from getting lost we "safe" link files
being unlinked. This link will be deleted in the same transaction with last
item of file. mounting the filesystem we scan all these links and remove
files which almost got lost */
void add_save_link(struct reiserfs_transaction_handle *th,
struct inode *inode, int truncate)
{
INITIALIZE_PATH(path);
int retval;
struct cpu_key key;
struct item_head ih;
__le32 link;
BUG_ON(!th->t_trans_id);
/* file can only get one "save link" of each kind */
RFALSE(truncate &&
(REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
"saved link already exists for truncated inode %lx",
(long)inode->i_ino);
RFALSE(!truncate &&
(REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
"saved link already exists for unlinked inode %lx",
(long)inode->i_ino);
/* setup key of "save" link */
key.version = KEY_FORMAT_3_5;
key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
key.on_disk_key.k_objectid = inode->i_ino;
if (!truncate) {
/* unlink, rmdir, rename */
set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
set_cpu_key_k_type(&key, TYPE_DIRECT);
/* item head of "safe" link */
make_le_item_head(&ih, &key, key.version,
1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
4 /*length */ , 0xffff /*free space */ );
} else {
/* truncate */
if (S_ISDIR(inode->i_mode))
reiserfs_warning(inode->i_sb,
"green-2102: Adding a truncate savelink for a directory %k! Please report",
INODE_PKEY(inode));
set_cpu_key_k_offset(&key, 1);
set_cpu_key_k_type(&key, TYPE_INDIRECT);
/* item head of "safe" link */
make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
4 /*length */ , 0 /*free space */ );
}
key.key_length = 3;
/* look for its place in the tree */
retval = search_item(inode->i_sb, &key, &path);
if (retval != ITEM_NOT_FOUND) {
if (retval != -ENOSPC)
reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:"
"search_by_key (%K) returned %d", &key,
retval);
pathrelse(&path);
return;
}
/* body of "save" link */
link = INODE_PKEY(inode)->k_dir_id;
/* put "save" link inot tree, don't charge quota to anyone */
retval =
reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
if (retval) {
if (retval != -ENOSPC)
reiserfs_warning(inode->i_sb,
"vs-2120: add_save_link: insert_item returned %d",
retval);
} else {
if (truncate)
REISERFS_I(inode)->i_flags |=
i_link_saved_truncate_mask;
else
REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
}
}
/* this opens transaction unlike add_save_link */
int remove_save_link(struct inode *inode, int truncate)
{
struct reiserfs_transaction_handle th;
struct reiserfs_key key;
int err;
/* we are going to do one balancing only */
err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
if (err)
return err;
/* setup key of "save" link */
key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
key.k_objectid = INODE_PKEY(inode)->k_objectid;
if (!truncate) {
/* unlink, rmdir, rename */
set_le_key_k_offset(KEY_FORMAT_3_5, &key,
1 + inode->i_sb->s_blocksize);
set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
} else {
/* truncate */
set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
}
if ((truncate &&
(REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
(!truncate &&
(REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
/* don't take quota bytes from anywhere */
reiserfs_delete_solid_item(&th, NULL, &key);
if (!truncate) {
reiserfs_release_objectid(&th, inode->i_ino);
REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
} else
REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
}
static void reiserfs_kill_sb(struct super_block *s)
{
if (REISERFS_SB(s)) {
#ifdef CONFIG_REISERFS_FS_XATTR
if (REISERFS_SB(s)->xattr_root) {
d_invalidate(REISERFS_SB(s)->xattr_root);
dput(REISERFS_SB(s)->xattr_root);
REISERFS_SB(s)->xattr_root = NULL;
}
#endif
if (REISERFS_SB(s)->priv_root) {
d_invalidate(REISERFS_SB(s)->priv_root);
dput(REISERFS_SB(s)->priv_root);
REISERFS_SB(s)->priv_root = NULL;
}
}
kill_block_super(s);
}
static void reiserfs_put_super(struct super_block *s)
{
struct reiserfs_transaction_handle th;
th.t_trans_id = 0;
/* change file system state to current state if it was mounted with read-write permissions */
if (!(s->s_flags & MS_RDONLY)) {
if (!journal_begin(&th, s, 10)) {
reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
1);
set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
REISERFS_SB(s)->s_mount_state);
journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
}
}
/* note, journal_release checks for readonly mount, and can decide not
** to do a journal_end
*/
journal_release(&th, s);
reiserfs_free_bitmap_cache(s);
brelse(SB_BUFFER_WITH_SB(s));
print_statistics(s);
if (REISERFS_SB(s)->reserved_blocks != 0) {
reiserfs_warning(s,
"green-2005: reiserfs_put_super: reserved blocks left %d",
REISERFS_SB(s)->reserved_blocks);
}
reiserfs_proc_info_done(s);
kfree(s->s_fs_info);
s->s_fs_info = NULL;
return;
}
static struct kmem_cache *reiserfs_inode_cachep;
static struct inode *reiserfs_alloc_inode(struct super_block *sb)
{
struct reiserfs_inode_info *ei;
ei = (struct reiserfs_inode_info *)
kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL);
if (!ei)
return NULL;
return &ei->vfs_inode;
}
static void reiserfs_destroy_inode(struct inode *inode)
{
kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
}
static void init_once(void *foo)
{
struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
INIT_LIST_HEAD(&ei->i_prealloc_list);
inode_init_once(&ei->vfs_inode);
#ifdef CONFIG_REISERFS_FS_POSIX_ACL
ei->i_acl_access = NULL;
ei->i_acl_default = NULL;
#endif
}
static int init_inodecache(void)
{
reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
sizeof(struct
reiserfs_inode_info),
0, (SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD),
init_once);
if (reiserfs_inode_cachep == NULL)
return -ENOMEM;
return 0;
}
static void destroy_inodecache(void)
{
kmem_cache_destroy(reiserfs_inode_cachep);
}
/* we don't mark inodes dirty, we just log them */
static void reiserfs_dirty_inode(struct inode *inode)
{
struct reiserfs_transaction_handle th;
int err = 0;
if (inode->i_sb->s_flags & MS_RDONLY) {
reiserfs_warning(inode->i_sb,
"clm-6006: writing inode %lu on readonly FS",
inode->i_ino);
return;
}
reiserfs_write_lock(inode->i_sb);
/* this is really only used for atime updates, so they don't have
** to be included in O_SYNC or fsync
*/
err = journal_begin(&th, inode->i_sb, 1);
if (err) {
reiserfs_write_unlock(inode->i_sb);
return;
}
reiserfs_update_sd(&th, inode);
journal_end(&th, inode->i_sb, 1);
reiserfs_write_unlock(inode->i_sb);
}
#ifdef CONFIG_REISERFS_FS_POSIX_ACL
static void reiserfs_clear_inode(struct inode *inode)
{
struct posix_acl *acl;
acl = REISERFS_I(inode)->i_acl_access;
if (acl && !IS_ERR(acl))
posix_acl_release(acl);
REISERFS_I(inode)->i_acl_access = NULL;
acl = REISERFS_I(inode)->i_acl_default;
if (acl && !IS_ERR(acl))
posix_acl_release(acl);
REISERFS_I(inode)->i_acl_default = NULL;
}
#else
#define reiserfs_clear_inode NULL
#endif
#ifdef CONFIG_QUOTA
static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
size_t, loff_t);
static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
loff_t);
#endif
static const struct super_operations reiserfs_sops = {
.alloc_inode = reiserfs_alloc_inode,
.destroy_inode = reiserfs_destroy_inode,
.write_inode = reiserfs_write_inode,
.dirty_inode = reiserfs_dirty_inode,
.delete_inode = reiserfs_delete_inode,
.clear_inode = reiserfs_clear_inode,
.put_super = reiserfs_put_super,
.write_super = reiserfs_write_super,
.sync_fs = reiserfs_sync_fs,
.write_super_lockfs = reiserfs_write_super_lockfs,
.unlockfs = reiserfs_unlockfs,
.statfs = reiserfs_statfs,
.remount_fs = reiserfs_remount,
.show_options = generic_show_options,
#ifdef CONFIG_QUOTA
.quota_read = reiserfs_quota_read,
.quota_write = reiserfs_quota_write,
#endif
};
#ifdef CONFIG_QUOTA
#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
static int reiserfs_dquot_initialize(struct inode *, int);
static int reiserfs_dquot_drop(struct inode *);
static int reiserfs_write_dquot(struct dquot *);
static int reiserfs_acquire_dquot(struct dquot *);
static int reiserfs_release_dquot(struct dquot *);
static int reiserfs_mark_dquot_dirty(struct dquot *);
static int reiserfs_write_info(struct super_block *, int);
static int reiserfs_quota_on(struct super_block *, int, int, char *, int);
static struct dquot_operations reiserfs_quota_operations = {
.initialize = reiserfs_dquot_initialize,
.drop = reiserfs_dquot_drop,
.alloc_space = dquot_alloc_space,
.alloc_inode = dquot_alloc_inode,
.free_space = dquot_free_space,
.free_inode = dquot_free_inode,
.transfer = dquot_transfer,
.write_dquot = reiserfs_write_dquot,
.acquire_dquot = reiserfs_acquire_dquot,
.release_dquot = reiserfs_release_dquot,
.mark_dirty = reiserfs_mark_dquot_dirty,
.write_info = reiserfs_write_info,
};
static struct quotactl_ops reiserfs_qctl_operations = {
.quota_on = reiserfs_quota_on,
.quota_off = vfs_quota_off,
.quota_sync = vfs_quota_sync,
.get_info = vfs_get_dqinfo,
.set_info = vfs_set_dqinfo,
.get_dqblk = vfs_get_dqblk,
.set_dqblk = vfs_set_dqblk,
};
#endif
static const struct export_operations reiserfs_export_ops = {
.encode_fh = reiserfs_encode_fh,
.fh_to_dentry = reiserfs_fh_to_dentry,
.fh_to_parent = reiserfs_fh_to_parent,
.get_parent = reiserfs_get_parent,
};
/* this struct is used in reiserfs_getopt () for containing the value for those
mount options that have values rather than being toggles. */
typedef struct {
char *value;
int setmask; /* bitmask which is to set on mount_options bitmask when this
value is found, 0 is no bits are to be changed. */
int clrmask; /* bitmask which is to clear on mount_options bitmask when this
value is found, 0 is no bits are to be changed. This is
applied BEFORE setmask */
} arg_desc_t;
/* Set this bit in arg_required to allow empty arguments */
#define REISERFS_OPT_ALLOWEMPTY 31
/* this struct is used in reiserfs_getopt() for describing the set of reiserfs
mount options */
typedef struct {
char *option_name;
int arg_required; /* 0 if argument is not required, not 0 otherwise */
const arg_desc_t *values; /* list of values accepted by an option */
int setmask; /* bitmask which is to set on mount_options bitmask when this
value is found, 0 is no bits are to be changed. */
int clrmask; /* bitmask which is to clear on mount_options bitmask when this
value is found, 0 is no bits are to be changed. This is
applied BEFORE setmask */
} opt_desc_t;
/* possible values for -o data= */
static const arg_desc_t logging_mode[] = {
{"ordered", 1 << REISERFS_DATA_ORDERED,
(1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
{"journal", 1 << REISERFS_DATA_LOG,
(1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
{"writeback", 1 << REISERFS_DATA_WRITEBACK,
(1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
{.value = NULL}
};
/* possible values for -o barrier= */
static const arg_desc_t barrier_mode[] = {
{"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
{"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
{.value = NULL}
};
/* possible values for "-o block-allocator=" and bits which are to be set in
s_mount_opt of reiserfs specific part of in-core super block */
static const arg_desc_t balloc[] = {
{"noborder", 1 << REISERFS_NO_BORDER, 0},
{"border", 0, 1 << REISERFS_NO_BORDER},
{"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
{"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
{"test4", 1 << REISERFS_TEST4, 0},
{"notest4", 0, 1 << REISERFS_TEST4},
{NULL, 0, 0}
};
static const arg_desc_t tails[] = {
{"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
{"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
{"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
{NULL, 0, 0}
};
static const arg_desc_t error_actions[] = {
{"panic", 1 << REISERFS_ERROR_PANIC,
(1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
{"ro-remount", 1 << REISERFS_ERROR_RO,
(1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
#ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
{"continue", 1 << REISERFS_ERROR_CONTINUE,
(1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
#endif
{NULL, 0, 0},
};
/* proceed only one option from a list *cur - string containing of mount options
opts - array of options which are accepted
opt_arg - if option is found and requires an argument and if it is specifed
in the input - pointer to the argument is stored here
bit_flags - if option requires to set a certain bit - it is set here
return -1 if unknown option is found, opt->arg_required otherwise */
static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
char **opt_arg, unsigned long *bit_flags)
{
char *p;
/* foo=bar,
^ ^ ^
| | +-- option_end
| +-- arg_start
+-- option_start
*/
const opt_desc_t *opt;
const arg_desc_t *arg;
p = *cur;
/* assume argument cannot contain commas */
*cur = strchr(p, ',');
if (*cur) {
*(*cur) = '\0';
(*cur)++;
}
if (!strncmp(p, "alloc=", 6)) {
/* Ugly special case, probably we should redo options parser so that
it can understand several arguments for some options, also so that
it can fill several bitfields with option values. */
if (reiserfs_parse_alloc_options(s, p + 6)) {
return -1;
} else {
return 0;
}
}
/* for every option in the list */
for (opt = opts; opt->option_name; opt++) {
if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
if (bit_flags) {
if (opt->clrmask ==
(1 << REISERFS_UNSUPPORTED_OPT))
reiserfs_warning(s, "%s not supported.",
p);
else
*bit_flags &= ~opt->clrmask;
if (opt->setmask ==
(1 << REISERFS_UNSUPPORTED_OPT))
reiserfs_warning(s, "%s not supported.",
p);
else
*bit_flags |= opt->setmask;
}
break;
}
}
if (!opt->option_name) {
reiserfs_warning(s, "unknown mount option \"%s\"", p);
return -1;
}
p += strlen(opt->option_name);
switch (*p) {
case '=':
if (!opt->arg_required) {
reiserfs_warning(s,
"the option \"%s\" does not require an argument",
opt->option_name);
return -1;
}
break;
case 0:
if (opt->arg_required) {
reiserfs_warning(s,
"the option \"%s\" requires an argument",
opt->option_name);
return -1;
}
break;
default:
reiserfs_warning(s, "head of option \"%s\" is only correct",
opt->option_name);
return -1;
}
/* move to the argument, or to next option if argument is not required */
p++;
if (opt->arg_required
&& !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
&& !strlen(p)) {
/* this catches "option=," if not allowed */
reiserfs_warning(s, "empty argument for \"%s\"",
opt->option_name);
return -1;
}
if (!opt->values) {
/* *=NULLopt_arg contains pointer to argument */
*opt_arg = p;
return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
}
/* values possible for this option are listed in opt->values */
for (arg = opt->values; arg->value; arg++) {
if (!strcmp(p, arg->value)) {
if (bit_flags) {
*bit_flags &= ~arg->clrmask;
*bit_flags |= arg->setmask;
}
return opt->arg_required;
}
}
reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p,
opt->option_name);
return -1;
}
/* returns 0 if something is wrong in option string, 1 - otherwise */
static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
unsigned long *mount_options,
/* after the parsing phase, contains the
collection of bitflags defining what
mount options were selected. */
unsigned long *blocks, /* strtol-ed from NNN of resize=NNN */
char **jdev_name,
unsigned int *commit_max_age,
char **qf_names,
unsigned int *qfmt)
{
int c;
char *arg = NULL;
char *pos;
opt_desc_t opts[] = {
/* Compatibility stuff, so that -o notail for old setups still work */
{"tails",.arg_required = 't',.values = tails},
{"notail",.clrmask =
(1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
{"conv",.setmask = 1 << REISERFS_CONVERT},
{"attrs",.setmask = 1 << REISERFS_ATTRS},
{"noattrs",.clrmask = 1 << REISERFS_ATTRS},
#ifdef CONFIG_REISERFS_FS_XATTR
{"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
{"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
#else
{"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
{"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
#endif
#ifdef CONFIG_REISERFS_FS_POSIX_ACL
{"acl",.setmask = 1 << REISERFS_POSIXACL},
{"noacl",.clrmask = 1 << REISERFS_POSIXACL},
#else
{"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
{"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
#endif
{.option_name = "nolog"},
{"replayonly",.setmask = 1 << REPLAYONLY},
{"block-allocator",.arg_required = 'a',.values = balloc},
{"data",.arg_required = 'd',.values = logging_mode},
{"barrier",.arg_required = 'b',.values = barrier_mode},
{"resize",.arg_required = 'r',.values = NULL},
{"jdev",.arg_required = 'j',.values = NULL},
{"nolargeio",.arg_required = 'w',.values = NULL},
{"commit",.arg_required = 'c',.values = NULL},
{"usrquota",.setmask = 1 << REISERFS_QUOTA},
{"grpquota",.setmask = 1 << REISERFS_QUOTA},
{"noquota",.clrmask = 1 << REISERFS_QUOTA},
{"errors",.arg_required = 'e',.values = error_actions},
{"usrjquota",.arg_required =
'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
{"grpjquota",.arg_required =
'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
{"jqfmt",.arg_required = 'f',.values = NULL},
{.option_name = NULL}
};
*blocks = 0;
if (!options || !*options)
/* use default configuration: create tails, journaling on, no
conversion to newest format */
return 1;
for (pos = options; pos;) {
c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
if (c == -1)
/* wrong option is given */
return 0;
if (c == 'r') {
char *p;
p = NULL;
/* "resize=NNN" or "resize=auto" */
if (!strcmp(arg, "auto")) {
/* From JFS code, to auto-get the size. */
*blocks =
s->s_bdev->bd_inode->i_size >> s->
s_blocksize_bits;
} else {
*blocks = simple_strtoul(arg, &p, 0);
if (*p != '\0') {
/* NNN does not look like a number */
reiserfs_warning(s,
"reiserfs_parse_options: bad value %s",
arg);
return 0;
}
}
}
if (c == 'c') {
char *p = NULL;
unsigned long val = simple_strtoul(arg, &p, 0);
/* commit=NNN (time in seconds) */
if (*p != '\0' || val >= (unsigned int)-1) {
reiserfs_warning(s,
"reiserfs_parse_options: bad value %s",
arg);
return 0;
}
*commit_max_age = (unsigned int)val;
}
if (c == 'w') {
reiserfs_warning(s, "reiserfs: nolargeio option is no longer supported");
return 0;
}
if (c == 'j') {
if (arg && *arg && jdev_name) {
if (*jdev_name) { //Hm, already assigned?
reiserfs_warning(s,
"reiserfs_parse_options: journal device was already specified to be %s",
*jdev_name);
return 0;
}
*jdev_name = arg;
}
}
#ifdef CONFIG_QUOTA
if (c == 'u' || c == 'g') {
int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
if ((sb_any_quota_enabled(s) ||
sb_any_quota_suspended(s)) &&
(!*arg != !REISERFS_SB(s)->s_qf_names[qtype])) {
reiserfs_warning(s,