2 * Copyright 2005 by Hans Reiser, licensing governed by reiser4/README
6 * this file contains typical implementations for most of methods of struct
11 #include "../safe_link.h"
13 #include <linux/quotaops.h>
14 #include <linux/namei.h>
16 static int create_vfs_object(struct inode
*parent
, struct dentry
*dentry
,
17 reiser4_object_create_data
*data
);
20 * reiser4_create_common - create of inode operations
21 * @parent: inode of parent directory
22 * @dentry: dentry of new object to create
23 * @mode: the permissions to use
26 * This is common implementation of vfs's create method of struct
28 * Creates regular file using file plugin from parent directory plugin set.
30 int reiser4_create_common(struct inode
*parent
, struct dentry
*dentry
,
31 int mode
, struct nameidata
*nameidata
)
33 reiser4_object_create_data data
;
36 memset(&data
, 0, sizeof data
);
37 data
.mode
= S_IFREG
| mode
;
38 fplug
= child_create_plugin(parent
) ? : inode_create_plugin(parent
);
39 if (!plugin_of_group(fplug
, REISER4_REGULAR_FILE
)) {
40 warning("vpf-1900", "'%s' is not a regular file plugin.",
44 data
.id
= fplug
->h
.id
;
45 return create_vfs_object(parent
, dentry
, &data
);
48 int reiser4_lookup_name(struct inode
*dir
, struct dentry
*, reiser4_key
*);
49 void check_light_weight(struct inode
*inode
, struct inode
*parent
);
52 * reiser4_lookup_common - lookup of inode operations
53 * @parent: inode of directory to lookup into
54 * @dentry: name to look for
57 * This is common implementation of vfs's lookup method of struct
60 struct dentry
*reiser4_lookup_common(struct inode
*parent
,
61 struct dentry
*dentry
,
62 struct nameidata
*nameidata
)
68 reiser4_dir_entry_desc entry
;
70 ctx
= reiser4_init_context(parent
->i_sb
);
72 return (struct dentry
*)ctx
;
74 /* set up operations on dentry. */
75 dentry
->d_op
= &get_super_private(parent
->i_sb
)->ops
.dentry
;
77 result
= reiser4_lookup_name(parent
, dentry
, &entry
.key
);
79 context_set_commit_async(ctx
);
80 reiser4_exit_context(ctx
);
81 if (result
== -ENOENT
) {
82 /* object not found */
83 if (!IS_DEADDIR(parent
))
87 return ERR_PTR(result
);
90 inode
= reiser4_iget(parent
->i_sb
, &entry
.key
, 0);
92 context_set_commit_async(ctx
);
93 reiser4_exit_context(ctx
);
94 return ERR_PTR(PTR_ERR(inode
));
98 check_light_weight(inode
, parent
);
99 new = d_splice_alias(inode
, dentry
);
100 reiser4_iget_complete(inode
);
102 /* prevent balance_dirty_pages() from being called: we don't want to
103 * do this under directory i_mutex. */
104 context_set_commit_async(ctx
);
105 reiser4_exit_context(ctx
);
109 static reiser4_block_nr
common_estimate_link(struct inode
*parent
,
110 struct inode
*object
);
111 int reiser4_update_dir(struct inode
*);
114 * reiser4_link_common - link of inode operations
115 * @existing: dentry of object which is to get new name
116 * @parent: directory where new name is to be created
119 * This is common implementation of vfs's link method of struct
122 int reiser4_link_common(struct dentry
*existing
, struct inode
*parent
,
123 struct dentry
*newname
)
125 reiser4_context
*ctx
;
127 struct inode
*object
;
128 dir_plugin
*parent_dplug
;
129 reiser4_dir_entry_desc entry
;
130 reiser4_object_create_data data
;
131 reiser4_block_nr reserve
;
133 ctx
= reiser4_init_context(parent
->i_sb
);
137 assert("nikita-1431", existing
!= NULL
);
138 assert("nikita-1432", parent
!= NULL
);
139 assert("nikita-1433", newname
!= NULL
);
141 object
= existing
->d_inode
;
142 assert("nikita-1434", object
!= NULL
);
144 /* check for race with create_object() */
145 if (reiser4_inode_get_flag(object
, REISER4_IMMUTABLE
)) {
146 context_set_commit_async(ctx
);
147 reiser4_exit_context(ctx
);
148 return RETERR(-E_REPEAT
);
151 parent_dplug
= inode_dir_plugin(parent
);
153 memset(&entry
, 0, sizeof entry
);
156 data
.mode
= object
->i_mode
;
157 data
.id
= inode_file_plugin(object
)->h
.id
;
159 reserve
= common_estimate_link(parent
, existing
->d_inode
);
160 if ((__s64
) reserve
< 0) {
161 context_set_commit_async(ctx
);
162 reiser4_exit_context(ctx
);
166 if (reiser4_grab_space(reserve
, BA_CAN_COMMIT
)) {
167 context_set_commit_async(ctx
);
168 reiser4_exit_context(ctx
);
169 return RETERR(-ENOSPC
);
173 * Subtle race handling: sys_link() doesn't take i_mutex on @parent. It
174 * means that link(2) can race against unlink(2) or rename(2), and
175 * inode is dead (->i_nlink == 0) when reiser4_link() is entered.
177 * For such inode we have to undo special processing done in
178 * reiser4_unlink() viz. creation of safe-link.
180 if (unlikely(object
->i_nlink
== 0)) {
181 result
= safe_link_del(reiser4_tree_by_inode(object
),
182 get_inode_oid(object
), SAFE_UNLINK
);
184 context_set_commit_async(ctx
);
185 reiser4_exit_context(ctx
);
190 /* increment nlink of @existing and update its stat data */
191 result
= reiser4_add_nlink(object
, parent
, 1);
193 /* add entry to the parent */
195 parent_dplug
->add_entry(parent
, newname
, &data
, &entry
);
197 /* failed to add entry to the parent, decrement nlink
199 reiser4_del_nlink(object
, parent
, 1);
201 * now, if that failed, we have a file with too big
202 * nlink---space leak, much better than directory
203 * entry pointing to nowhere
208 atomic_inc(&object
->i_count
);
210 * Upon successful completion, link() shall mark for update
211 * the st_ctime field of the file. Also, the st_ctime and
212 * st_mtime fields of the directory that contains the new
213 * entry shall be marked for update. --SUS
215 result
= reiser4_update_dir(parent
);
218 d_instantiate(newname
, existing
->d_inode
);
220 context_set_commit_async(ctx
);
221 reiser4_exit_context(ctx
);
225 static int unlink_check_and_grab(struct inode
*parent
, struct dentry
*victim
);
228 * reiser4_unlink_common - unlink of inode operations
229 * @parent: inode of directory to remove name from
230 * @victim: name to be removed
232 * This is common implementation of vfs's unlink method of struct
235 int reiser4_unlink_common(struct inode
*parent
, struct dentry
*victim
)
237 reiser4_context
*ctx
;
239 struct inode
*object
;
242 ctx
= reiser4_init_context(parent
->i_sb
);
246 object
= victim
->d_inode
;
247 fplug
= inode_file_plugin(object
);
248 assert("nikita-2882", fplug
->detach
!= NULL
);
250 result
= unlink_check_and_grab(parent
, victim
);
252 context_set_commit_async(ctx
);
253 reiser4_exit_context(ctx
);
257 result
= fplug
->detach(object
, parent
);
259 dir_plugin
*parent_dplug
;
260 reiser4_dir_entry_desc entry
;
262 parent_dplug
= inode_dir_plugin(parent
);
263 memset(&entry
, 0, sizeof entry
);
265 /* first, delete directory entry */
266 result
= parent_dplug
->rem_entry(parent
, victim
, &entry
);
269 * if name was removed successfully, we _have_ to
270 * return 0 from this function, because upper level
271 * caller (vfs_{rmdir,unlink}) expect this.
273 * now that directory entry is removed, update
276 reiser4_del_nlink(object
, parent
, 1);
278 * Upon successful completion, unlink() shall mark for
279 * update the st_ctime and st_mtime fields of the
280 * parent directory. Also, if the file's link count is
281 * not 0, the st_ctime field of the file shall be
282 * marked for update. --SUS
284 reiser4_update_dir(parent
);
285 /* add safe-link for this file */
286 if (object
->i_nlink
== 0)
287 safe_link_add(object
, SAFE_UNLINK
);
291 if (unlikely(result
!= 0)) {
292 if (result
!= -ENOMEM
)
293 warning("nikita-3398", "Cannot unlink %llu (%i)",
294 (unsigned long long)get_inode_oid(object
),
296 /* if operation failed commit pending inode modifications to
298 reiser4_update_sd(object
);
299 reiser4_update_sd(parent
);
302 reiser4_release_reserved(object
->i_sb
);
304 /* @object's i_ctime was updated by ->rem_link() method(). */
306 /* @victim can be already removed from the disk by this time. Inode is
307 then marked so that iput() wouldn't try to remove stat data. But
308 inode itself is still there.
312 * we cannot release directory semaphore here, because name has
313 * already been deleted, but dentry (@victim) still exists. Prevent
314 * balance_dirty_pages() from being called on exiting this context: we
315 * don't want to do this under directory i_mutex.
317 context_set_commit_async(ctx
);
318 reiser4_exit_context(ctx
);
323 * reiser4_symlink_common - symlink of inode operations
324 * @parent: inode of parent directory
325 * @dentry: dentry of object to be created
326 * @linkname: string symlink is to contain
328 * This is common implementation of vfs's symlink method of struct
330 * Creates object using file plugin SYMLINK_FILE_PLUGIN_ID.
332 int reiser4_symlink_common(struct inode
*parent
, struct dentry
*dentry
,
333 const char *linkname
)
335 reiser4_object_create_data data
;
337 memset(&data
, 0, sizeof data
);
338 data
.name
= linkname
;
339 data
.id
= SYMLINK_FILE_PLUGIN_ID
;
340 data
.mode
= S_IFLNK
| S_IRWXUGO
;
341 return create_vfs_object(parent
, dentry
, &data
);
345 * reiser4_mkdir_common - mkdir of inode operations
346 * @parent: inode of parent directory
347 * @dentry: dentry of object to be created
348 * @mode: the permissions to use
350 * This is common implementation of vfs's mkdir method of struct
352 * Creates object using file plugin DIRECTORY_FILE_PLUGIN_ID.
354 int reiser4_mkdir_common(struct inode
*parent
, struct dentry
*dentry
, int mode
)
356 reiser4_object_create_data data
;
358 memset(&data
, 0, sizeof data
);
359 data
.mode
= S_IFDIR
| mode
;
360 data
.id
= DIRECTORY_FILE_PLUGIN_ID
;
361 return create_vfs_object(parent
, dentry
, &data
);
365 * reiser4_mknod_common - mknod of inode operations
366 * @parent: inode of parent directory
367 * @dentry: dentry of object to be created
368 * @mode: the permissions to use and file type
369 * @rdev: minor and major of new device file
371 * This is common implementation of vfs's mknod method of struct
373 * Creates object using file plugin SPECIAL_FILE_PLUGIN_ID.
375 int reiser4_mknod_common(struct inode
*parent
, struct dentry
*dentry
,
376 int mode
, dev_t rdev
)
378 reiser4_object_create_data data
;
380 memset(&data
, 0, sizeof data
);
383 data
.id
= SPECIAL_FILE_PLUGIN_ID
;
384 return create_vfs_object(parent
, dentry
, &data
);
388 * implementation of vfs's rename method of struct inode_operations for typical
389 * directory is in inode_ops_rename.c
393 * reiser4_follow_link_common - follow_link of inode operations
394 * @dentry: dentry of symlink
397 * This is common implementation of vfs's followlink method of struct
399 * Assumes that inode's i_private points to the content of symbolic link.
401 void *reiser4_follow_link_common(struct dentry
*dentry
, struct nameidata
*nd
)
403 assert("vs-851", S_ISLNK(dentry
->d_inode
->i_mode
));
405 if (!dentry
->d_inode
->i_private
406 || !reiser4_inode_get_flag(dentry
->d_inode
,
407 REISER4_GENERIC_PTR_USED
))
408 return ERR_PTR(RETERR(-EINVAL
));
409 nd_set_link(nd
, dentry
->d_inode
->i_private
);
414 * reiser4_permission_common - permission of inode operations
415 * @inode: inode to check permissions for
416 * @mask: mode bits to check permissions for
419 * Uses generic function to check for rwx permissions.
421 int reiser4_permission_common(struct inode
*inode
, int mask
)
423 return generic_permission(inode
, mask
, NULL
);
426 static int setattr_reserve(reiser4_tree
*);
428 /* this is common implementation of vfs's setattr method of struct
431 int reiser4_setattr_common(struct dentry
*dentry
, struct iattr
*attr
)
433 reiser4_context
*ctx
;
437 inode
= dentry
->d_inode
;
438 result
= inode_change_ok(inode
, attr
);
442 ctx
= reiser4_init_context(inode
->i_sb
);
446 assert("nikita-3119", !(attr
->ia_valid
& ATTR_SIZE
));
449 * grab disk space and call standard inode_setattr().
451 result
= setattr_reserve(reiser4_tree_by_inode(inode
));
453 if ((attr
->ia_valid
& ATTR_UID
&& attr
->ia_uid
!= inode
->i_uid
)
454 || (attr
->ia_valid
& ATTR_GID
455 && attr
->ia_gid
!= inode
->i_gid
)) {
456 result
= vfs_dq_transfer(inode
, attr
) ? -EDQUOT
: 0;
458 context_set_commit_async(ctx
);
459 reiser4_exit_context(ctx
);
463 result
= inode_setattr(inode
, attr
);
465 reiser4_update_sd(inode
);
468 context_set_commit_async(ctx
);
469 reiser4_exit_context(ctx
);
473 /* this is common implementation of vfs's getattr method of struct
476 int reiser4_getattr_common(struct vfsmount
*mnt UNUSED_ARG
,
477 struct dentry
*dentry
, struct kstat
*stat
)
481 assert("nikita-2298", dentry
!= NULL
);
482 assert("nikita-2299", stat
!= NULL
);
483 assert("nikita-2300", dentry
->d_inode
!= NULL
);
485 obj
= dentry
->d_inode
;
487 stat
->dev
= obj
->i_sb
->s_dev
;
488 stat
->ino
= oid_to_uino(get_inode_oid(obj
));
489 stat
->mode
= obj
->i_mode
;
490 /* don't confuse userland with huge nlink. This is not entirely
491 * correct, because nlink_t is not necessary 16 bit signed. */
492 stat
->nlink
= min(obj
->i_nlink
, (typeof(obj
->i_nlink
)) 0x7fff);
493 stat
->uid
= obj
->i_uid
;
494 stat
->gid
= obj
->i_gid
;
495 stat
->rdev
= obj
->i_rdev
;
496 stat
->atime
= obj
->i_atime
;
497 stat
->mtime
= obj
->i_mtime
;
498 stat
->ctime
= obj
->i_ctime
;
499 stat
->size
= obj
->i_size
;
501 (inode_get_bytes(obj
) + VFS_BLKSIZE
- 1) >> VFS_BLKSIZE_BITS
;
502 /* "preferred" blocksize for efficient file system I/O */
503 stat
->blksize
= get_super_private(obj
->i_sb
)->optimal_io_size
;
508 /* Estimate the maximum amount of nodes which might be allocated or changed on
509 typical new object creation. Typical creation consists of calling create
510 method of file plugin, adding directory entry to parent and update parent
511 directory's stat data.
513 static reiser4_block_nr
estimate_create_vfs_object(struct inode
*parent
,
518 assert("vpf-309", parent
!= NULL
);
519 assert("vpf-307", object
!= NULL
);
522 /* object creation estimation */
523 inode_file_plugin(object
)->estimate
.create(object
) +
524 /* stat data of parent directory estimation */
525 inode_file_plugin(parent
)->estimate
.update(parent
) +
526 /* adding entry estimation */
527 inode_dir_plugin(parent
)->estimate
.add_entry(parent
) +
528 /* to undo in the case of failure */
529 inode_dir_plugin(parent
)->estimate
.rem_entry(parent
);
532 /* Create child in directory.
534 . get object's plugin
537 . add object's stat-data
538 . initialize object's directory
539 . add entry to the parent
543 static int do_create_vfs_child(reiser4_object_create_data
* data
,/* parameters
546 struct inode
**retobj
)
550 struct dentry
*dentry
; /* parent object */
551 struct inode
*parent
; /* new name */
553 dir_plugin
*par_dir
; /* directory plugin on the parent */
554 dir_plugin
*obj_dir
; /* directory plugin on the new object */
555 file_plugin
*obj_plug
; /* object plugin on the new object */
556 struct inode
*object
; /* new object */
557 reiser4_block_nr reserve
;
559 reiser4_dir_entry_desc entry
; /* new directory entry */
561 assert("nikita-1420", data
!= NULL
);
562 parent
= data
->parent
;
563 dentry
= data
->dentry
;
565 assert("nikita-1418", parent
!= NULL
);
566 assert("nikita-1419", dentry
!= NULL
);
568 /* check, that name is acceptable for parent */
569 par_dir
= inode_dir_plugin(parent
);
570 if (par_dir
->is_name_acceptable
&&
571 !par_dir
->is_name_acceptable(parent
,
573 (int)dentry
->d_name
.len
))
574 return RETERR(-ENAMETOOLONG
);
577 obj_plug
= file_plugin_by_id((int)data
->id
);
578 if (obj_plug
== NULL
) {
579 warning("nikita-430", "Cannot find plugin %i", data
->id
);
580 return RETERR(-ENOENT
);
582 object
= new_inode(parent
->i_sb
);
584 return RETERR(-ENOMEM
);
585 /* we'll update i_nlink below */
587 /* new_inode() initializes i_ino to "arbitrary" value. Reset it to 0,
588 * to simplify error handling: if some error occurs before i_ino is
589 * initialized with oid, i_ino should already be set to some
590 * distinguished value. */
593 /* So that on error iput will be called. */
596 if (vfs_dq_alloc_inode(object
)) {
598 object
->i_flags
|= S_NOQUOTA
;
599 return RETERR(-EDQUOT
);
602 memset(&entry
, 0, sizeof entry
);
605 set_plugin(&reiser4_inode_data(object
)->pset
, PSET_FILE
,
606 file_plugin_to_plugin(obj_plug
));
607 result
= obj_plug
->set_plug_in_inode(object
, parent
, data
);
609 warning("nikita-431", "Cannot install plugin %i on %llx",
610 data
->id
, (unsigned long long)get_inode_oid(object
));
611 vfs_dq_free_inode(object
);
612 object
->i_flags
|= S_NOQUOTA
;
616 /* reget plugin after installation */
617 obj_plug
= inode_file_plugin(object
);
619 if (obj_plug
->create_object
== NULL
) {
620 vfs_dq_free_inode(object
);
621 object
->i_flags
|= S_NOQUOTA
;
622 return RETERR(-EPERM
);
625 /* if any of hash, tail, sd or permission plugins for newly created
626 object are not set yet set them here inheriting them from parent
629 assert("nikita-2070", obj_plug
->adjust_to_parent
!= NULL
);
630 result
= obj_plug
->adjust_to_parent(object
,
632 object
->i_sb
->s_root
->d_inode
);
634 result
= finish_pset(object
);
636 warning("nikita-432", "Cannot inherit from %llx to %llx",
637 (unsigned long long)get_inode_oid(parent
),
638 (unsigned long long)get_inode_oid(object
));
639 vfs_dq_free_inode(object
);
640 object
->i_flags
|= S_NOQUOTA
;
644 /* setup inode and file-operations for this inode */
645 setup_inode_ops(object
, data
);
647 /* call file plugin's method to initialize plugin specific part of
649 if (obj_plug
->init_inode_data
)
650 obj_plug
->init_inode_data(object
, data
, 1/*create */);
652 /* obtain directory plugin (if any) for new object. */
653 obj_dir
= inode_dir_plugin(object
);
654 if (obj_dir
!= NULL
&& obj_dir
->init
== NULL
) {
655 vfs_dq_free_inode(object
);
656 object
->i_flags
|= S_NOQUOTA
;
657 return RETERR(-EPERM
);
660 reiser4_inode_data(object
)->locality_id
= get_inode_oid(parent
);
662 reserve
= estimate_create_vfs_object(parent
, object
);
663 if (reiser4_grab_space(reserve
, BA_CAN_COMMIT
)) {
664 vfs_dq_free_inode(object
);
665 object
->i_flags
|= S_NOQUOTA
;
666 return RETERR(-ENOSPC
);
669 /* mark inode `immutable'. We disable changes to the file being
670 created until valid directory entry for it is inserted. Otherwise,
671 if file were expanded and insertion of directory entry fails, we
672 have to remove file, but we only alloted enough space in
673 transaction to remove _empty_ file. 3.x code used to remove stat
674 data in different transaction thus possibly leaking disk space on
675 crash. This all only matters if it's possible to access file
676 without name, for example, by inode number
678 reiser4_inode_set_flag(object
, REISER4_IMMUTABLE
);
680 /* create empty object, this includes allocation of new objectid. For
681 directories this implies creation of dot and dotdot */
682 assert("nikita-2265", reiser4_inode_get_flag(object
, REISER4_NO_SD
));
684 /* mark inode as `loaded'. From this point onward
685 reiser4_delete_inode() will try to remove its stat-data. */
686 reiser4_inode_set_flag(object
, REISER4_LOADED
);
688 result
= obj_plug
->create_object(object
, parent
, data
);
690 reiser4_inode_clr_flag(object
, REISER4_IMMUTABLE
);
691 if (result
!= -ENAMETOOLONG
&& result
!= -ENOMEM
)
692 warning("nikita-2219",
693 "Failed to create sd for %llu",
694 (unsigned long long)get_inode_oid(object
));
695 vfs_dq_free_inode(object
);
696 object
->i_flags
|= S_NOQUOTA
;
701 result
= obj_dir
->init(object
, parent
, data
);
703 assert("nikita-434", !reiser4_inode_get_flag(object
,
705 /* insert inode into VFS hash table */
706 insert_inode_hash(object
);
708 result
= par_dir
->add_entry(parent
, dentry
, data
, &entry
);
710 result
= reiser4_add_nlink(object
, parent
, 0);
711 /* If O_CREAT is set and the file did not previously
712 exist, upon successful completion, open() shall
713 mark for update the st_atime, st_ctime, and
714 st_mtime fields of the file and the st_ctime and
715 st_mtime fields of the parent directory. --SUS
717 /* @object times are already updated by
718 reiser4_add_nlink() */
720 reiser4_update_dir(parent
);
722 /* cleanup failure to add nlink */
723 par_dir
->rem_entry(parent
, dentry
, &entry
);
726 /* cleanup failure to add entry */
727 obj_plug
->detach(object
, parent
);
728 } else if (result
!= -ENOMEM
)
729 warning("nikita-2219", "Failed to initialize dir for %llu: %i",
730 (unsigned long long)get_inode_oid(object
), result
);
733 * update stat-data, committing all pending modifications to the inode
736 reiser4_update_sd(object
);
738 vfs_dq_free_inode(object
);
739 object
->i_flags
|= S_NOQUOTA
;
740 /* if everything was ok (result == 0), parent stat-data is
741 * already updated above (update_parent_dir()) */
742 reiser4_update_sd(parent
);
743 /* failure to create entry, remove object */
744 obj_plug
->delete_object(object
);
747 /* file has name now, clear immutable flag */
748 reiser4_inode_clr_flag(object
, REISER4_IMMUTABLE
);
750 /* on error, iput() will call ->delete_inode(). We should keep track
751 of the existence of stat-data for this inode and avoid attempt to
752 remove it in reiser4_delete_inode(). This is accomplished through
753 REISER4_NO_SD bit in inode.u.reiser4_i.plugin.flags
758 /* this is helper for common implementations of reiser4_mkdir, reiser4_create,
759 reiser4_mknod and reiser4_symlink
762 create_vfs_object(struct inode
*parent
,
763 struct dentry
*dentry
, reiser4_object_create_data
* data
)
765 reiser4_context
*ctx
;
769 ctx
= reiser4_init_context(parent
->i_sb
);
772 context_set_commit_async(ctx
);
774 data
->parent
= parent
;
775 data
->dentry
= dentry
;
777 result
= do_create_vfs_child(data
, &child
);
778 if (unlikely(result
!= 0)) {
780 reiser4_make_bad_inode(child
);
784 d_instantiate(dentry
, child
);
786 reiser4_exit_context(ctx
);
791 * helper for link_common. Estimate disk space necessary to add a link
792 * from @parent to @object
794 static reiser4_block_nr
common_estimate_link(struct inode
*parent
/* parent
797 struct inode
*object
/* object to
803 reiser4_block_nr res
= 0;
807 assert("vpf-317", object
!= NULL
);
808 assert("vpf-318", parent
!= NULL
);
810 fplug
= inode_file_plugin(object
);
811 dplug
= inode_dir_plugin(parent
);
812 /* VS-FIXME-HANS: why do we do fplug->estimate.update(object) twice
813 * instead of multiplying by 2? */
814 /* reiser4_add_nlink(object) */
815 res
+= fplug
->estimate
.update(object
);
816 /* add_entry(parent) */
817 res
+= dplug
->estimate
.add_entry(parent
);
818 /* reiser4_del_nlink(object) */
819 res
+= fplug
->estimate
.update(object
);
820 /* update_dir(parent) */
821 res
+= inode_file_plugin(parent
)->estimate
.update(parent
);
823 res
+= estimate_one_item_removal(reiser4_tree_by_inode(object
));
828 /* Estimate disk space necessary to remove a link between @parent and
831 static reiser4_block_nr
estimate_unlink(struct inode
*parent
/* parent
833 struct inode
*object
/* object to which
838 reiser4_block_nr res
= 0;
842 assert("vpf-317", object
!= NULL
);
843 assert("vpf-318", parent
!= NULL
);
845 fplug
= inode_file_plugin(object
);
846 dplug
= inode_dir_plugin(parent
);
848 /* rem_entry(parent) */
849 res
+= dplug
->estimate
.rem_entry(parent
);
850 /* reiser4_del_nlink(object) */
851 res
+= fplug
->estimate
.update(object
);
852 /* update_dir(parent) */
853 res
+= inode_file_plugin(parent
)->estimate
.update(parent
);
855 res
+= fplug
->estimate
.unlink(object
, parent
);
857 res
+= estimate_one_insert_item(reiser4_tree_by_inode(object
));
862 /* helper for reiser4_unlink_common. Estimate and grab space for unlink. */
863 static int unlink_check_and_grab(struct inode
*parent
, struct dentry
*victim
)
870 child
= victim
->d_inode
;
871 fplug
= inode_file_plugin(child
);
873 /* check for race with create_object() */
874 if (reiser4_inode_get_flag(child
, REISER4_IMMUTABLE
))
875 return RETERR(-E_REPEAT
);
876 /* object being deleted should have stat data */
877 assert("vs-949", !reiser4_inode_get_flag(child
, REISER4_NO_SD
));
879 /* ask object plugin */
880 if (fplug
->can_rem_link
!= NULL
&& !fplug
->can_rem_link(child
))
881 return RETERR(-ENOTEMPTY
);
883 result
= (int)estimate_unlink(parent
, child
);
887 return reiser4_grab_reserved(child
->i_sb
, result
, BA_CAN_COMMIT
);
890 /* helper for reiser4_setattr_common */
891 static int setattr_reserve(reiser4_tree
* tree
)
893 assert("vs-1096", is_grab_enabled(get_current_context()));
894 return reiser4_grab_space(estimate_one_insert_into_item(tree
),
898 /* helper function. Standards require that for many file-system operations
899 on success ctime and mtime of parent directory is to be updated. */
900 int reiser4_update_dir(struct inode
*dir
)
902 assert("nikita-2525", dir
!= NULL
);
904 dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME
;
905 return reiser4_update_sd(dir
);