1 /* Copyright 2005 by Hans Reiser, licensing governed by
4 /* this file contains typical implementations for most of methods of
10 #include "../safe_link.h"
12 #include <linux/quotaops.h>
14 static int insert_new_sd(struct inode
*inode
);
15 static int update_sd(struct inode
*inode
);
17 /* this is common implementation of write_sd_by_inode method of file plugin
18 either insert stat data or update it
20 int write_sd_by_inode_common(struct inode
*inode
/* object to save */)
24 assert("nikita-730", inode
!= NULL
);
26 if (reiser4_inode_get_flag(inode
, REISER4_NO_SD
))
27 /* object doesn't have stat-data yet */
28 result
= insert_new_sd(inode
);
30 result
= update_sd(inode
);
31 if (result
!= 0 && result
!= -ENAMETOOLONG
&& result
!= -ENOMEM
)
32 /* Don't issue warnings about "name is too long" */
33 warning("nikita-2221", "Failed to save sd for %llu: %i",
34 (unsigned long long)get_inode_oid(inode
), result
);
38 /* this is common implementation of key_by_inode method of file plugin
41 key_by_inode_and_offset_common(struct inode
*inode
, loff_t off
,
44 reiser4_key_init(key
);
45 set_key_locality(key
, reiser4_inode_data(inode
)->locality_id
);
46 set_key_ordering(key
, get_inode_ordering(inode
));
47 set_key_objectid(key
, get_inode_oid(inode
)); /*FIXME: inode->i_ino */
48 set_key_type(key
, KEY_BODY_MINOR
);
49 set_key_offset(key
, (__u64
) off
);
53 /* this is common implementation of set_plug_in_inode method of file plugin
55 int set_plug_in_inode_common(struct inode
*object
/* inode to set plugin on */ ,
56 struct inode
*parent
/* parent object */ ,
57 reiser4_object_create_data
* data
/* creational
62 object
->i_mode
= data
->mode
;
63 /* this should be plugin decision */
64 object
->i_uid
= current_fsuid();
65 object
->i_mtime
= object
->i_atime
= object
->i_ctime
= CURRENT_TIME
;
67 /* support for BSD style group-id assignment. See mount's manual page
68 description of bsdgroups ext2 mount options for more details */
69 if (reiser4_is_set(object
->i_sb
, REISER4_BSD_GID
))
70 object
->i_gid
= parent
->i_gid
;
71 else if (parent
->i_mode
& S_ISGID
) {
72 /* parent directory has sguid bit */
73 object
->i_gid
= parent
->i_gid
;
74 if (S_ISDIR(object
->i_mode
))
75 /* sguid is inherited by sub-directories */
76 object
->i_mode
|= S_ISGID
;
78 object
->i_gid
= current_fsgid();
80 /* this object doesn't have stat-data yet */
81 reiser4_inode_set_flag(object
, REISER4_NO_SD
);
83 /* this is now called after all inode plugins are initialized:
84 do_create_vfs_child after adjust_to_parent */
85 /* setup inode and file-operations for this inode */
86 setup_inode_ops(object
, data
);
89 reiser4_seal_init(&reiser4_inode_data(object
)->sd_seal
, NULL
, NULL
);
90 mask
= (1 << UNIX_STAT
) | (1 << LIGHT_WEIGHT_STAT
);
91 if (!reiser4_is_set(object
->i_sb
, REISER4_32_BIT_TIMES
))
92 mask
|= (1 << LARGE_TIMES_STAT
);
94 reiser4_inode_data(object
)->extmask
= mask
;
98 /* this is common implementation of adjust_to_parent method of file plugin for
101 int adjust_to_parent_common(struct inode
*object
/* new object */ ,
102 struct inode
*parent
/* parent directory */ ,
103 struct inode
*root
/* root directory */)
105 assert("nikita-2165", object
!= NULL
);
108 assert("nikita-2069", parent
!= NULL
);
111 * inherit missing plugins from parent
114 grab_plugin_pset(object
, parent
, PSET_FILE
);
115 grab_plugin_pset(object
, parent
, PSET_SD
);
116 grab_plugin_pset(object
, parent
, PSET_FORMATTING
);
117 grab_plugin_pset(object
, parent
, PSET_PERM
);
121 /* this is common implementation of adjust_to_parent method of file plugin for
124 int adjust_to_parent_common_dir(struct inode
*object
/* new object */ ,
125 struct inode
*parent
/* parent directory */ ,
126 struct inode
*root
/* root directory */)
131 assert("nikita-2166", object
!= NULL
);
134 assert("nikita-2167", parent
!= NULL
);
137 * inherit missing plugins from parent
139 for (memb
= 0; memb
< PSET_LAST
; ++memb
) {
140 result
= grab_plugin_pset(object
, parent
, memb
);
147 int adjust_to_parent_cryptcompress(struct inode
*object
/* new object */ ,
148 struct inode
*parent
/* parent directory */,
149 struct inode
*root
/* root directory */)
152 result
= adjust_to_parent_common(object
, parent
, root
);
155 assert("edward-1416", parent
!= NULL
);
157 grab_plugin_pset(object
, parent
, PSET_CLUSTER
);
158 grab_plugin_pset(object
, parent
, PSET_CIPHER
);
159 grab_plugin_pset(object
, parent
, PSET_DIGEST
);
160 grab_plugin_pset(object
, parent
, PSET_COMPRESSION
);
161 grab_plugin_pset(object
, parent
, PSET_COMPRESSION_MODE
);
166 /* this is common implementation of create_object method of file plugin
168 int reiser4_create_object_common(struct inode
*object
, struct inode
*parent
,
169 reiser4_object_create_data
* data
)
171 reiser4_block_nr reserve
;
172 assert("nikita-744", object
!= NULL
);
173 assert("nikita-745", parent
!= NULL
);
174 assert("nikita-747", data
!= NULL
);
175 assert("nikita-748", reiser4_inode_get_flag(object
, REISER4_NO_SD
));
177 reserve
= estimate_create_common(object
);
178 if (reiser4_grab_space(reserve
, BA_CAN_COMMIT
))
179 return RETERR(-ENOSPC
);
180 return write_sd_by_inode_common(object
);
183 static int common_object_delete_no_reserve(struct inode
*inode
);
186 * reiser4_delete_object_common - delete_object of file_plugin
187 * @inode: inode to be deleted
189 * This is common implementation of delete_object method of file_plugin. It
190 * applies to object its deletion consists of removing two items - stat data
193 int reiser4_delete_object_common(struct inode
*inode
)
197 assert("nikita-1477", inode
!= NULL
);
198 /* FIXME: if file body deletion failed (i/o error, for instance),
199 inode->i_size can be != 0 here */
200 assert("nikita-3420", inode
->i_size
== 0 || S_ISLNK(inode
->i_mode
));
201 assert("nikita-3421", inode
->i_nlink
== 0);
203 if (!reiser4_inode_get_flag(inode
, REISER4_NO_SD
)) {
204 reiser4_block_nr reserve
;
206 /* grab space which is needed to remove 2 items from the tree:
207 stat data and safe-link */
209 estimate_one_item_removal(reiser4_tree_by_inode(inode
));
210 if (reiser4_grab_space_force(reserve
,
211 BA_RESERVED
| BA_CAN_COMMIT
))
212 return RETERR(-ENOSPC
);
213 result
= common_object_delete_no_reserve(inode
);
220 * reiser4_delete_dir_common - delete_object of file_plugin
221 * @inode: inode to be deleted
223 * This is common implementation of delete_object method of file_plugin for
224 * typical directory. It calls done method of dir_plugin to remove "." and
225 * removes stat data and safe-link.
227 int reiser4_delete_dir_common(struct inode
*inode
)
232 assert("", (get_current_context() &&
233 get_current_context()->trans
->atom
== NULL
));
235 dplug
= inode_dir_plugin(inode
);
236 assert("vs-1101", dplug
&& dplug
->done
);
238 /* kill cursors which might be attached to inode */
239 reiser4_kill_cursors(inode
);
241 /* grab space enough for removing two items */
242 if (reiser4_grab_space
243 (2 * estimate_one_item_removal(reiser4_tree_by_inode(inode
)),
244 BA_RESERVED
| BA_CAN_COMMIT
))
245 return RETERR(-ENOSPC
);
247 result
= dplug
->done(inode
);
249 result
= common_object_delete_no_reserve(inode
);
253 /* this is common implementation of add_link method of file plugin
255 int reiser4_add_link_common(struct inode
*object
, struct inode
*parent
)
258 * increment ->i_nlink and update ->i_ctime
261 INODE_INC_FIELD(object
, i_nlink
);
262 object
->i_ctime
= CURRENT_TIME
;
266 /* this is common implementation of rem_link method of file plugin
268 int reiser4_rem_link_common(struct inode
*object
, struct inode
*parent
)
270 assert("nikita-2021", object
!= NULL
);
271 assert("nikita-2163", object
->i_nlink
> 0);
274 * decrement ->i_nlink and update ->i_ctime
277 INODE_DEC_FIELD(object
, i_nlink
);
278 object
->i_ctime
= CURRENT_TIME
;
282 /* this is common implementation of rem_link method of file plugin for typical
285 int rem_link_common_dir(struct inode
*object
, struct inode
*parent UNUSED_ARG
)
287 assert("nikita-20211", object
!= NULL
);
288 assert("nikita-21631", object
->i_nlink
> 0);
291 * decrement ->i_nlink and update ->i_ctime
293 INODE_DEC_FIELD(object
, i_nlink
);
294 if (object
->i_nlink
== 1)
295 INODE_DEC_FIELD(object
, i_nlink
);
296 object
->i_ctime
= CURRENT_TIME
;
300 /* this is common implementation of owns_item method of file plugin
301 compare objectids of keys in inode and coord */
302 int owns_item_common(const struct inode
*inode
, /* object to check
304 const coord_t
*coord
/* coord to check */)
306 reiser4_key item_key
;
307 reiser4_key file_key
;
309 assert("nikita-760", inode
!= NULL
);
310 assert("nikita-761", coord
!= NULL
);
312 return coord_is_existing_item(coord
) &&
313 (get_key_objectid(build_sd_key(inode
, &file_key
)) ==
314 get_key_objectid(item_key_by_coord(coord
, &item_key
)));
317 /* this is common implementation of owns_item method of file plugin
318 for typical directory
320 int owns_item_common_dir(const struct inode
*inode
,/* object to check against */
321 const coord_t
*coord
/* coord of item to check */)
323 reiser4_key item_key
;
325 assert("nikita-1335", inode
!= NULL
);
326 assert("nikita-1334", coord
!= NULL
);
328 if (plugin_of_group(item_plugin_by_coord(coord
), DIR_ENTRY_ITEM_TYPE
))
329 return get_key_locality(item_key_by_coord(coord
, &item_key
)) ==
330 get_inode_oid(inode
);
332 return owns_item_common(inode
, coord
);
335 /* this is common implementation of can_add_link method of file plugin
336 checks whether yet another hard links to this object can be added
338 int can_add_link_common(const struct inode
*object
/* object to check */)
340 assert("nikita-732", object
!= NULL
);
342 /* inode->i_nlink is unsigned int, so just check for integer
344 return object
->i_nlink
+ 1 != 0;
347 /* this is common implementation of can_rem_link method of file plugin for
350 int can_rem_link_common_dir(const struct inode
*inode
)
352 /* is_dir_empty() returns 0 is dir is empty */
353 return !is_dir_empty(inode
);
356 /* this is common implementation of detach method of file plugin for typical
359 int reiser4_detach_common_dir(struct inode
*child
, struct inode
*parent
)
363 dplug
= inode_dir_plugin(child
);
364 assert("nikita-2883", dplug
!= NULL
);
365 assert("nikita-2884", dplug
->detach
!= NULL
);
366 return dplug
->detach(child
, parent
);
369 /* this is common implementation of bind method of file plugin for typical
372 int reiser4_bind_common_dir(struct inode
*child
, struct inode
*parent
)
376 dplug
= inode_dir_plugin(child
);
377 assert("nikita-2646", dplug
!= NULL
);
378 return dplug
->attach(child
, parent
);
381 static int process_truncate(struct inode
*, __u64 size
);
383 /* this is common implementation of safelink method of file plugin
385 int safelink_common(struct inode
*object
, reiser4_safe_link_t link
, __u64 value
)
389 assert("vs-1705", get_current_context()->trans
->atom
== NULL
);
390 if (link
== SAFE_UNLINK
)
391 /* nothing to do. iput() in the caller (process_safelink) will
392 * finish with file */
394 else if (link
== SAFE_TRUNCATE
)
395 result
= process_truncate(object
, value
);
397 warning("nikita-3438", "Unrecognized safe-link type: %i", link
);
398 result
= RETERR(-EIO
);
403 /* this is common implementation of estimate.create method of file plugin
404 can be used when object creation involves insertion of one item (usually stat
407 reiser4_block_nr
estimate_create_common(const struct inode
*object
)
409 return estimate_one_insert_item(reiser4_tree_by_inode(object
));
412 /* this is common implementation of estimate.create method of file plugin for
414 can be used when directory creation involves insertion of two items (usually
415 stat data and item containing "." and "..") into tree
417 reiser4_block_nr
estimate_create_common_dir(const struct inode
*object
)
419 return 2 * estimate_one_insert_item(reiser4_tree_by_inode(object
));
422 /* this is common implementation of estimate.update method of file plugin
423 can be used when stat data update does not do more than inserting a unit
424 into a stat data item which is probably true for most cases
426 reiser4_block_nr
estimate_update_common(const struct inode
*inode
)
428 return estimate_one_insert_into_item(reiser4_tree_by_inode(inode
));
431 /* this is common implementation of estimate.unlink method of file plugin
434 estimate_unlink_common(const struct inode
*object UNUSED_ARG
,
435 const struct inode
*parent UNUSED_ARG
)
440 /* this is common implementation of estimate.unlink method of file plugin for
444 estimate_unlink_common_dir(const struct inode
*object
,
445 const struct inode
*parent
)
449 dplug
= inode_dir_plugin(object
);
450 assert("nikita-2888", dplug
!= NULL
);
451 assert("nikita-2887", dplug
->estimate
.unlink
!= NULL
);
452 return dplug
->estimate
.unlink(object
, parent
);
455 char *wire_write_common(struct inode
*inode
, char *start
)
457 return build_inode_onwire(inode
, start
);
460 char *wire_read_common(char *addr
, reiser4_object_on_wire
* obj
)
463 return locate_obj_key_id_onwire(addr
);
464 return extract_obj_key_id_from_onwire(addr
, &obj
->u
.std
.key_id
);
467 struct dentry
*wire_get_common(struct super_block
*sb
,
468 reiser4_object_on_wire
* obj
)
471 struct dentry
*dentry
;
474 extract_key_from_id(&obj
->u
.std
.key_id
, &key
);
475 inode
= reiser4_iget(sb
, &key
, 1);
476 if (!IS_ERR(inode
)) {
477 reiser4_iget_complete(inode
);
478 dentry
= d_obtain_alias(inode
);
480 dentry
->d_op
= &get_super_private(sb
)->ops
.dentry
;
481 } else if (PTR_ERR(inode
) == -ENOENT
)
483 * inode wasn't found at the key encoded in the file
484 * handle. Hence, file handle is stale.
486 dentry
= ERR_PTR(RETERR(-ESTALE
));
488 dentry
= (void *)inode
;
492 int wire_size_common(struct inode
*inode
)
494 return inode_onwire_size(inode
);
497 void wire_done_common(reiser4_object_on_wire
* obj
)
502 /* helper function to print errors */
503 static void key_warning(const reiser4_key
* key
/* key to print */ ,
504 const struct inode
*inode
,
505 int code
/* error code to print */)
507 assert("nikita-716", key
!= NULL
);
509 if (code
!= -ENOMEM
) {
510 warning("nikita-717", "Error for inode %llu (%i)",
511 (unsigned long long)get_key_objectid(key
), code
);
512 reiser4_print_key("for key", key
);
516 /* NIKITA-FIXME-HANS: perhaps this function belongs in another file? */
519 check_inode_seal(const struct inode
*inode
,
520 const coord_t
*coord
, const reiser4_key
* key
)
522 reiser4_key unit_key
;
524 unit_key_by_coord(coord
, &unit_key
);
525 assert("nikita-2752",
526 WITH_DATA_RET(coord
->node
, 1, keyeq(key
, &unit_key
)));
527 assert("nikita-2753", get_inode_oid(inode
) == get_key_objectid(key
));
530 static void check_sd_coord(coord_t
*coord
, const reiser4_key
* key
)
534 coord_clear_iplug(coord
);
535 if (zload(coord
->node
))
538 if (!coord_is_existing_unit(coord
) ||
539 !item_plugin_by_coord(coord
) ||
540 !keyeq(unit_key_by_coord(coord
, &ukey
), key
) ||
541 (znode_get_level(coord
->node
) != LEAF_LEVEL
) ||
542 !item_is_statdata(coord
)) {
543 warning("nikita-1901", "Conspicuous seal");
544 reiser4_print_key("key", key
);
545 print_coord("coord", coord
, 1);
546 impossible("nikita-2877", "no way");
552 #define check_inode_seal(inode, coord, key) noop
553 #define check_sd_coord(coord, key) noop
556 /* insert new stat-data into tree. Called with inode state
557 locked. Return inode state locked. */
558 static int insert_new_sd(struct inode
*inode
/* inode to create sd for */)
563 reiser4_item_data data
;
569 assert("nikita-723", inode
!= NULL
);
570 assert("nikita-3406", reiser4_inode_get_flag(inode
, REISER4_NO_SD
));
572 ref
= reiser4_inode_data(inode
);
573 spin_lock_inode(inode
);
575 if (ref
->plugin_mask
!= 0)
576 /* inode has non-standard plugins */
577 inode_set_extension(inode
, PLUGIN_STAT
);
579 * prepare specification of new item to be inserted
582 data
.iplug
= inode_sd_plugin(inode
);
583 data
.length
= data
.iplug
->s
.sd
.save_len(inode
);
584 spin_unlock_inode(inode
);
588 /* could be optimized for case where there is only one node format in
589 * use in the filesystem, probably there are lots of such
590 * places we could optimize for only one node layout.... -Hans */
591 if (data
.length
> reiser4_tree_by_inode(inode
)->nplug
->max_item_size()) {
592 /* This is silly check, but we don't know actual node where
593 insertion will go into. */
594 return RETERR(-ENAMETOOLONG
);
596 oid
= oid_allocate(inode
->i_sb
);
597 /* NIKITA-FIXME-HANS: what is your opinion on whether this error check should be
598 * encapsulated into oid_allocate? */
599 if (oid
== ABSOLUTE_MAX_OID
)
600 return RETERR(-EOVERFLOW
);
602 set_inode_oid(inode
, oid
);
604 coord_init_zero(&coord
);
607 result
= insert_by_key(reiser4_tree_by_inode(inode
),
608 build_sd_key(inode
, &key
), &data
, &coord
, &lh
,
609 /* stat data lives on a leaf level */
610 LEAF_LEVEL
, CBK_UNIQUE
);
612 /* we don't want to re-check that somebody didn't insert
613 stat-data while we were doing io, because if it did,
614 insert_by_key() returned error. */
615 /* but what _is_ possible is that plugin for inode's stat-data,
616 list of non-standard plugins or their state would change
617 during io, so that stat-data wouldn't fit into sd. To avoid
618 this race we keep inode_state lock. This lock has to be
619 taken each time you access inode in a way that would cause
620 changes in sd size: changing plugins etc.
623 if (result
== IBK_INSERT_OK
) {
624 coord_clear_iplug(&coord
);
625 result
= zload(coord
.node
);
627 /* have we really inserted stat data? */
628 assert("nikita-725", item_is_statdata(&coord
));
630 /* inode was just created. It is inserted into hash
631 table, but no directory entry was yet inserted into
632 parent. So, inode is inaccessible through
633 ->lookup(). All places that directly grab inode
634 from hash-table (like old knfsd), should check
635 IMMUTABLE flag that is set by common_create_child.
637 assert("nikita-3240", data
.iplug
!= NULL
);
638 assert("nikita-3241", data
.iplug
->s
.sd
.save
!= NULL
);
639 area
= item_body_by_coord(&coord
);
640 result
= data
.iplug
->s
.sd
.save(inode
, &area
);
641 znode_make_dirty(coord
.node
);
643 /* object has stat-data now */
644 reiser4_inode_clr_flag(inode
, REISER4_NO_SD
);
645 reiser4_inode_set_flag(inode
,
646 REISER4_SDLEN_KNOWN
);
647 /* initialise stat-data seal */
648 reiser4_seal_init(&ref
->sd_seal
, &coord
, &key
);
649 ref
->sd_coord
= coord
;
650 check_inode_seal(inode
, &coord
, &key
);
651 } else if (result
!= -ENOMEM
)
653 * convert any other error code to -EIO to
654 * avoid confusing user level with unexpected
657 result
= RETERR(-EIO
);
664 key_warning(&key
, inode
, result
);
666 oid_count_allocated();
671 /* find sd of inode in a tree, deal with errors */
672 int lookup_sd(struct inode
*inode
/* inode to look sd for */ ,
673 znode_lock_mode lock_mode
/* lock mode */ ,
674 coord_t
*coord
/* resulting coord */ ,
675 lock_handle
* lh
/* resulting lock handle */ ,
676 const reiser4_key
* key
/* resulting key */ ,
682 assert("nikita-1692", inode
!= NULL
);
683 assert("nikita-1693", coord
!= NULL
);
684 assert("nikita-1694", key
!= NULL
);
686 /* look for the object's stat data in a tree.
687 This returns in "node" pointer to a locked znode and in "pos"
688 position of an item found in node. Both are only valid if
689 coord_found is returned. */
690 flags
= (lock_mode
== ZNODE_WRITE_LOCK
) ? CBK_FOR_INSERT
: 0;
693 * traverse tree to find stat data. We cannot use vroot here, because
694 * it only covers _body_ of the file, and stat data don't belong
697 result
= coord_by_key(reiser4_tree_by_inode(inode
),
702 FIND_EXACT
, LEAF_LEVEL
, LEAF_LEVEL
, flags
, NULL
);
703 if (REISER4_DEBUG
&& result
== 0)
704 check_sd_coord(coord
, key
);
706 if (result
!= 0 && !silent
)
707 key_warning(key
, inode
, result
);
712 locate_inode_sd(struct inode
*inode
,
713 reiser4_key
* key
, coord_t
*coord
, lock_handle
* lh
)
715 reiser4_inode
*state
;
719 assert("nikita-3483", inode
!= NULL
);
721 state
= reiser4_inode_data(inode
);
722 spin_lock_inode(inode
);
723 *coord
= state
->sd_coord
;
724 coord_clear_iplug(coord
);
725 seal
= state
->sd_seal
;
726 spin_unlock_inode(inode
);
728 build_sd_key(inode
, key
);
729 if (reiser4_seal_is_set(&seal
)) {
730 /* first, try to use seal */
731 result
= reiser4_seal_validate(&seal
,
734 lh
, ZNODE_WRITE_LOCK
,
737 check_sd_coord(coord
, key
);
742 coord_init_zero(coord
);
743 result
= lookup_sd(inode
, ZNODE_WRITE_LOCK
, coord
, lh
, key
, 0);
749 static int all_but_offset_key_eq(const reiser4_key
* k1
, const reiser4_key
* k2
)
751 return (get_key_locality(k1
) == get_key_locality(k2
) &&
752 get_key_type(k1
) == get_key_type(k2
) &&
753 get_key_band(k1
) == get_key_band(k2
) &&
754 get_key_ordering(k1
) == get_key_ordering(k2
) &&
755 get_key_objectid(k1
) == get_key_objectid(k2
));
758 #include "../tree_walk.h"
760 /* make some checks before and after stat-data resize operation */
761 static int check_sd_resize(struct inode
*inode
, coord_t
*coord
,
762 int length
, int progress
/* 1 means after resize */)
765 lock_handle left_lock
;
767 reiser4_key left_key
;
770 if (inode_file_plugin(inode
) !=
771 file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID
))
775 if (coord
->item_pos
!= 0)
779 ret
= reiser4_get_left_neighbor(&left_lock
,
782 GN_CAN_USE_UPPER_LEVELS
);
783 if (ret
== -E_REPEAT
|| ret
== -E_NO_NEIGHBOR
||
784 ret
== -ENOENT
|| ret
== -EINVAL
785 || ret
== -E_DEADLOCK
) {
789 ret
= zload(left_lock
.node
);
792 coord_init_last_unit(&left_coord
, left_lock
.node
);
793 item_key_by_coord(&left_coord
, &left_key
);
794 item_key_by_coord(coord
, &key
);
796 if (all_but_offset_key_eq(&key
, &left_key
))
797 /* corruption occured */
799 zrelse(left_lock
.node
);
806 /* update stat-data at @coord */
808 update_sd_at(struct inode
*inode
, coord_t
*coord
, reiser4_key
* key
,
812 reiser4_item_data data
;
814 reiser4_inode
*state
;
817 state
= reiser4_inode_data(inode
);
819 coord_clear_iplug(coord
);
820 result
= zload(coord
->node
);
823 loaded
= coord
->node
;
825 spin_lock_inode(inode
);
826 assert("nikita-728", inode_sd_plugin(inode
) != NULL
);
827 data
.iplug
= inode_sd_plugin(inode
);
829 /* if inode has non-standard plugins, add appropriate stat data
831 if (state
->extmask
& (1 << PLUGIN_STAT
)) {
832 if (state
->plugin_mask
== 0)
833 inode_clr_extension(inode
, PLUGIN_STAT
);
834 } else if (state
->plugin_mask
!= 0)
835 inode_set_extension(inode
, PLUGIN_STAT
);
837 if (state
->extmask
& (1 << HEIR_STAT
)) {
838 if (state
->heir_mask
== 0)
839 inode_clr_extension(inode
, HEIR_STAT
);
840 } else if (state
->heir_mask
!= 0)
841 inode_set_extension(inode
, HEIR_STAT
);
843 /* data.length is how much space to add to (or remove
844 from if negative) sd */
845 if (!reiser4_inode_get_flag(inode
, REISER4_SDLEN_KNOWN
)) {
846 /* recalculate stat-data length */
848 data
.iplug
->s
.sd
.save_len(inode
) -
849 item_length_by_coord(coord
);
850 reiser4_inode_set_flag(inode
, REISER4_SDLEN_KNOWN
);
853 spin_unlock_inode(inode
);
855 /* if on-disk stat data is of different length than required
856 for this inode, resize it */
858 if (data
.length
!= 0) {
862 assert("edward-1441",
863 !check_sd_resize(inode
, coord
,
864 data
.length
, 0/* before resize */));
866 /* insertion code requires that insertion point (coord) was
868 coord
->between
= AFTER_UNIT
;
869 result
= reiser4_resize_item(coord
, &data
, key
, lh
,
870 COPI_DONT_SHIFT_LEFT
);
872 key_warning(key
, inode
, result
);
876 if (loaded
!= coord
->node
) {
877 /* reiser4_resize_item moved coord to another node.
880 coord_clear_iplug(coord
);
881 result
= zload(coord
->node
);
884 loaded
= coord
->node
;
886 assert("edward-1442",
887 !check_sd_resize(inode
, coord
,
888 data
.length
, 1/* after resize */));
890 area
= item_body_by_coord(coord
);
891 spin_lock_inode(inode
);
892 result
= data
.iplug
->s
.sd
.save(inode
, &area
);
893 znode_make_dirty(coord
->node
);
895 /* re-initialise stat-data seal */
898 * coord.between was possibly skewed from AT_UNIT when stat-data size
899 * was changed and new extensions were pasted into item.
901 coord
->between
= AT_UNIT
;
902 reiser4_seal_init(&state
->sd_seal
, coord
, key
);
903 state
->sd_coord
= *coord
;
904 spin_unlock_inode(inode
);
905 check_inode_seal(inode
, coord
, key
);
910 /* Update existing stat-data in a tree. Called with inode state locked. Return
911 inode state locked. */
912 static int update_sd(struct inode
*inode
/* inode to update sd for */)
919 assert("nikita-726", inode
!= NULL
);
921 /* no stat-data, nothing to update?! */
922 assert("nikita-3482", !reiser4_inode_get_flag(inode
, REISER4_NO_SD
));
926 result
= locate_inode_sd(inode
, &key
, &coord
, &lh
);
928 result
= update_sd_at(inode
, &coord
, &key
, &lh
);
934 /* helper for reiser4_delete_object_common and reiser4_delete_dir_common.
935 Remove object stat data. Space for that must be reserved by caller before
938 common_object_delete_no_reserve(struct inode
*inode
/* object to remove */)
942 assert("nikita-1477", inode
!= NULL
);
944 if (!reiser4_inode_get_flag(inode
, REISER4_NO_SD
)) {
947 vfs_dq_free_inode(inode
);
950 build_sd_key(inode
, &sd_key
);
952 reiser4_cut_tree(reiser4_tree_by_inode(inode
),
953 &sd_key
, &sd_key
, NULL
, 0);
955 reiser4_inode_set_flag(inode
, REISER4_NO_SD
);
956 result
= oid_release(inode
->i_sb
, get_inode_oid(inode
));
958 oid_count_released();
960 result
= safe_link_del(reiser4_tree_by_inode(inode
),
961 get_inode_oid(inode
),
970 /* helper for safelink_common */
971 static int process_truncate(struct inode
*inode
, __u64 size
)
976 reiser4_context
*ctx
;
977 struct dentry dentry
;
979 assert("vs-21", is_in_reiser4_context());
980 ctx
= reiser4_init_context(inode
->i_sb
);
981 assert("vs-22", !IS_ERR(ctx
));
984 attr
.ia_valid
= ATTR_SIZE
| ATTR_CTIME
;
985 fplug
= inode_file_plugin(inode
);
987 mutex_lock(&inode
->i_mutex
);
988 assert("vs-1704", get_current_context()->trans
->atom
== NULL
);
989 dentry
.d_inode
= inode
;
990 result
= inode
->i_op
->setattr(&dentry
, &attr
);
991 mutex_unlock(&inode
->i_mutex
);
993 context_set_commit_async(ctx
);
994 reiser4_exit_context(ctx
);
1001 c-indentation-style: "K&R"