mm-only debug patch...
[mmotm.git] / fs / reiser4 / oid.c
blob623f52c6f9d788cd824c47290fc76882af6e6dd6
1 /* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
3 #include "debug.h"
4 #include "super.h"
5 #include "txnmgr.h"
7 /* we used to have oid allocation plugin. It was removed because it
8 was recognized as providing unneeded level of abstraction. If one
9 ever will find it useful - look at yet_unneeded_abstractions/oid
13 * initialize in-memory data for oid allocator at @super. @nr_files and @next
14 * are provided by disk format plugin that reads them from the disk during
15 * mount.
17 int oid_init_allocator(struct super_block *super, oid_t nr_files, oid_t next)
19 reiser4_super_info_data *sbinfo;
21 sbinfo = get_super_private(super);
23 sbinfo->next_to_use = next;
24 sbinfo->oids_in_use = nr_files;
25 return 0;
29 * allocate oid and return it. ABSOLUTE_MAX_OID is returned when allocator
30 * runs out of oids.
32 oid_t oid_allocate(struct super_block *super)
34 reiser4_super_info_data *sbinfo;
35 oid_t oid;
37 sbinfo = get_super_private(super);
39 spin_lock_reiser4_super(sbinfo);
40 if (sbinfo->next_to_use != ABSOLUTE_MAX_OID) {
41 oid = sbinfo->next_to_use++;
42 sbinfo->oids_in_use++;
43 } else
44 oid = ABSOLUTE_MAX_OID;
45 spin_unlock_reiser4_super(sbinfo);
46 return oid;
50 * Tell oid allocator that @oid is now free.
52 int oid_release(struct super_block *super, oid_t oid UNUSED_ARG)
54 reiser4_super_info_data *sbinfo;
56 sbinfo = get_super_private(super);
58 spin_lock_reiser4_super(sbinfo);
59 sbinfo->oids_in_use--;
60 spin_unlock_reiser4_super(sbinfo);
61 return 0;
65 * return next @oid that would be allocated (i.e., returned by oid_allocate())
66 * without actually allocating it. This is used by disk format plugin to save
67 * oid allocator state on the disk.
69 oid_t oid_next(const struct super_block *super)
71 reiser4_super_info_data *sbinfo;
72 oid_t oid;
74 sbinfo = get_super_private(super);
76 spin_lock_reiser4_super(sbinfo);
77 oid = sbinfo->next_to_use;
78 spin_unlock_reiser4_super(sbinfo);
79 return oid;
83 * returns number of currently used oids. This is used by statfs(2) to report
84 * number of "inodes" and by disk format plugin to save oid allocator state on
85 * the disk.
87 long oids_used(const struct super_block *super)
89 reiser4_super_info_data *sbinfo;
90 oid_t used;
92 sbinfo = get_super_private(super);
94 spin_lock_reiser4_super(sbinfo);
95 used = sbinfo->oids_in_use;
96 spin_unlock_reiser4_super(sbinfo);
97 if (used < (__u64) ((long)~0) >> 1)
98 return (long)used;
99 else
100 return (long)-1;
104 * Count oid as allocated in atom. This is done after call to oid_allocate()
105 * at the point when we are irrevocably committed to creation of the new file
106 * (i.e., when oid allocation cannot be any longer rolled back due to some
107 * error).
109 void oid_count_allocated(void)
111 txn_atom *atom;
113 atom = get_current_atom_locked();
114 atom->nr_objects_created++;
115 spin_unlock_atom(atom);
119 * Count oid as free in atom. This is done after call to oid_release() at the
120 * point when we are irrevocably committed to the deletion of the file (i.e.,
121 * when oid release cannot be any longer rolled back due to some error).
123 void oid_count_released(void)
125 txn_atom *atom;
127 atom = get_current_atom_locked();
128 atom->nr_objects_deleted++;
129 spin_unlock_atom(atom);
133 Local variables:
134 c-indentation-style: "K&R"
135 mode-name: "LC"
136 c-basic-offset: 8
137 tab-width: 8
138 fill-column: 120
139 scroll-step: 1
140 End: