1 /* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
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
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
;
29 * allocate oid and return it. ABSOLUTE_MAX_OID is returned when allocator
32 oid_t
oid_allocate(struct super_block
*super
)
34 reiser4_super_info_data
*sbinfo
;
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
++;
44 oid
= ABSOLUTE_MAX_OID
;
45 spin_unlock_reiser4_super(sbinfo
);
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
);
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
;
74 sbinfo
= get_super_private(super
);
76 spin_lock_reiser4_super(sbinfo
);
77 oid
= sbinfo
->next_to_use
;
78 spin_unlock_reiser4_super(sbinfo
);
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
87 long oids_used(const struct super_block
*super
)
89 reiser4_super_info_data
*sbinfo
;
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)
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
109 void oid_count_allocated(void)
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)
127 atom
= get_current_atom_locked();
128 atom
->nr_objects_deleted
++;
129 spin_unlock_atom(atom
);
134 c-indentation-style: "K&R"