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
)
462 return extract_obj_key_id_from_onwire(addr
, &obj
->u
.std
.key_id
);
465 struct dentry
*wire_get_common(struct super_block
*sb
,
466 reiser4_object_on_wire
* obj
)
469 struct dentry
*dentry
;
472 extract_key_from_id(&obj
->u
.std
.key_id
, &key
);
473 inode
= reiser4_iget(sb
, &key
, 1);
474 if (!IS_ERR(inode
)) {
475 reiser4_iget_complete(inode
);
476 dentry
= d_alloc_anon(inode
);
477 if (dentry
== NULL
) {
479 dentry
= ERR_PTR(-ENOMEM
);
481 dentry
->d_op
= &get_super_private(sb
)->ops
.dentry
;
482 } else if (PTR_ERR(inode
) == -ENOENT
)
484 * inode wasn't found at the key encoded in the file
485 * handle. Hence, file handle is stale.
487 dentry
= ERR_PTR(RETERR(-ESTALE
));
489 dentry
= (void *)inode
;
493 int wire_size_common(struct inode
*inode
)
495 return inode_onwire_size(inode
);
498 void wire_done_common(reiser4_object_on_wire
* obj
)
503 /* helper function to print errors */
504 static void key_warning(const reiser4_key
* key
/* key to print */ ,
505 const struct inode
*inode
,
506 int code
/* error code to print */ )
508 assert("nikita-716", key
!= NULL
);
510 if (code
!= -ENOMEM
) {
511 warning("nikita-717", "Error for inode %llu (%i)",
512 (unsigned long long)get_key_objectid(key
), code
);
513 reiser4_print_key("for key", key
);
517 /* NIKITA-FIXME-HANS: perhaps this function belongs in another file? */
520 check_inode_seal(const struct inode
*inode
,
521 const coord_t
* coord
, const reiser4_key
* key
)
523 reiser4_key unit_key
;
525 unit_key_by_coord(coord
, &unit_key
);
526 assert("nikita-2752",
527 WITH_DATA_RET(coord
->node
, 1, keyeq(key
, &unit_key
)));
528 assert("nikita-2753", get_inode_oid(inode
) == get_key_objectid(key
));
531 static void check_sd_coord(coord_t
* coord
, const reiser4_key
* key
)
535 coord_clear_iplug(coord
);
536 if (zload(coord
->node
))
539 if (!coord_is_existing_unit(coord
) ||
540 !item_plugin_by_coord(coord
) ||
541 !keyeq(unit_key_by_coord(coord
, &ukey
), key
) ||
542 (znode_get_level(coord
->node
) != LEAF_LEVEL
) ||
543 !item_is_statdata(coord
)) {
544 warning("nikita-1901", "Conspicuous seal");
545 reiser4_print_key("key", key
);
546 print_coord("coord", coord
, 1);
547 impossible("nikita-2877", "no way");
553 #define check_inode_seal(inode, coord, key) noop
554 #define check_sd_coord(coord, key) noop
557 /* insert new stat-data into tree. Called with inode state
558 locked. Return inode state locked. */
559 static int insert_new_sd(struct inode
*inode
/* inode to create sd for */ )
564 reiser4_item_data data
;
570 assert("nikita-723", inode
!= NULL
);
571 assert("nikita-3406", reiser4_inode_get_flag(inode
, REISER4_NO_SD
));
573 ref
= reiser4_inode_data(inode
);
574 spin_lock_inode(inode
);
576 if (ref
->plugin_mask
!= 0)
577 /* inode has non-standard plugins */
578 inode_set_extension(inode
, PLUGIN_STAT
);
580 * prepare specification of new item to be inserted
583 data
.iplug
= inode_sd_plugin(inode
);
584 data
.length
= data
.iplug
->s
.sd
.save_len(inode
);
585 spin_unlock_inode(inode
);
589 /* could be optimized for case where there is only one node format in
590 * use in the filesystem, probably there are lots of such
591 * places we could optimize for only one node layout.... -Hans */
592 if (data
.length
> reiser4_tree_by_inode(inode
)->nplug
->max_item_size()){
593 /* This is silly check, but we don't know actual node where
594 insertion will go into. */
595 return RETERR(-ENAMETOOLONG
);
597 oid
= oid_allocate(inode
->i_sb
);
598 /* NIKITA-FIXME-HANS: what is your opinion on whether this error check should be 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
, REISER4_SDLEN_KNOWN
);
646 /* initialise stat-data seal */
647 reiser4_seal_init(&ref
->sd_seal
, &coord
, &key
);
648 ref
->sd_coord
= coord
;
649 check_inode_seal(inode
, &coord
, &key
);
650 } else if (result
!= -ENOMEM
)
652 * convert any other error code to -EIO to
653 * avoid confusing user level with unexpected
656 result
= RETERR(-EIO
);
663 key_warning(&key
, inode
, result
);
665 oid_count_allocated();
670 /* find sd of inode in a tree, deal with errors */
671 int lookup_sd(struct inode
*inode
/* inode to look sd for */ ,
672 znode_lock_mode lock_mode
/* lock mode */ ,
673 coord_t
* coord
/* resulting coord */ ,
674 lock_handle
* lh
/* resulting lock handle */ ,
675 const reiser4_key
* key
/* resulting key */ ,
681 assert("nikita-1692", inode
!= NULL
);
682 assert("nikita-1693", coord
!= NULL
);
683 assert("nikita-1694", key
!= NULL
);
685 /* look for the object's stat data in a tree.
686 This returns in "node" pointer to a locked znode and in "pos"
687 position of an item found in node. Both are only valid if
688 coord_found is returned. */
689 flags
= (lock_mode
== ZNODE_WRITE_LOCK
) ? CBK_FOR_INSERT
: 0;
692 * traverse tree to find stat data. We cannot use vroot here, because
693 * it only covers _body_ of the file, and stat data don't belong
696 result
= coord_by_key(reiser4_tree_by_inode(inode
),
701 FIND_EXACT
, LEAF_LEVEL
, LEAF_LEVEL
, flags
, NULL
);
702 if (REISER4_DEBUG
&& result
== 0)
703 check_sd_coord(coord
, key
);
705 if (result
!= 0 && !silent
)
706 key_warning(key
, inode
, result
);
711 locate_inode_sd(struct inode
*inode
,
712 reiser4_key
* key
, coord_t
* coord
, lock_handle
* lh
)
714 reiser4_inode
*state
;
718 assert("nikita-3483", inode
!= NULL
);
720 state
= reiser4_inode_data(inode
);
721 spin_lock_inode(inode
);
722 *coord
= state
->sd_coord
;
723 coord_clear_iplug(coord
);
724 seal
= state
->sd_seal
;
725 spin_unlock_inode(inode
);
727 build_sd_key(inode
, key
);
728 if (reiser4_seal_is_set(&seal
)) {
729 /* first, try to use seal */
730 result
= reiser4_seal_validate(&seal
,
733 lh
, ZNODE_WRITE_LOCK
,
736 check_sd_coord(coord
, key
);
741 coord_init_zero(coord
);
742 result
= lookup_sd(inode
, ZNODE_WRITE_LOCK
, coord
, lh
, key
, 0);
748 static int all_but_offset_key_eq(const reiser4_key
* k1
, const reiser4_key
* k2
)
750 return (get_key_locality(k1
) == get_key_locality(k2
) &&
751 get_key_type(k1
) == get_key_type(k2
) &&
752 get_key_band(k1
) == get_key_band(k2
) &&
753 get_key_ordering(k1
) == get_key_ordering(k2
) &&
754 get_key_objectid(k1
) == get_key_objectid(k2
));
757 #include "../tree_walk.h"
759 /* make some checks before and after stat-data resize operation */
760 static int check_sd_resize(struct inode
* inode
, coord_t
* coord
,
761 int length
, int progress
/* 1 means after resize */)
764 lock_handle left_lock
;
766 reiser4_key left_key
;
769 if (inode_file_plugin(inode
) !=
770 file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID
))
774 if (coord
->item_pos
!= 0)
778 ret
= reiser4_get_left_neighbor(&left_lock
,
781 GN_CAN_USE_UPPER_LEVELS
);
782 if (ret
== -E_REPEAT
|| ret
== -E_NO_NEIGHBOR
||
783 ret
== -ENOENT
|| ret
== -EINVAL
784 || ret
== -E_DEADLOCK
) {
788 ret
= zload(left_lock
.node
);
791 coord_init_last_unit(&left_coord
, left_lock
.node
);
792 item_key_by_coord(&left_coord
, &left_key
);
793 item_key_by_coord(coord
, &key
);
795 if (all_but_offset_key_eq(&key
, &left_key
))
796 /* corruption occured */
798 zrelse(left_lock
.node
);
805 /* update stat-data at @coord */
807 update_sd_at(struct inode
*inode
, coord_t
* coord
, reiser4_key
* key
,
811 reiser4_item_data data
;
813 reiser4_inode
*state
;
816 state
= reiser4_inode_data(inode
);
818 coord_clear_iplug(coord
);
819 result
= zload(coord
->node
);
822 loaded
= coord
->node
;
824 spin_lock_inode(inode
);
825 assert("nikita-728", inode_sd_plugin(inode
) != NULL
);
826 data
.iplug
= inode_sd_plugin(inode
);
828 /* if inode has non-standard plugins, add appropriate stat data
830 if (state
->extmask
& (1 << PLUGIN_STAT
)) {
831 if (state
->plugin_mask
== 0)
832 inode_clr_extension(inode
, PLUGIN_STAT
);
833 } else if (state
->plugin_mask
!= 0)
834 inode_set_extension(inode
, PLUGIN_STAT
);
836 if (state
->extmask
& (1 << HEIR_STAT
)) {
837 if (state
->heir_mask
== 0)
838 inode_clr_extension(inode
, HEIR_STAT
);
839 } else if (state
->heir_mask
!= 0)
840 inode_set_extension(inode
, HEIR_STAT
);
842 /* data.length is how much space to add to (or remove
843 from if negative) sd */
844 if (!reiser4_inode_get_flag(inode
, REISER4_SDLEN_KNOWN
)) {
845 /* recalculate stat-data length */
847 data
.iplug
->s
.sd
.save_len(inode
) -
848 item_length_by_coord(coord
);
849 reiser4_inode_set_flag(inode
, REISER4_SDLEN_KNOWN
);
852 spin_unlock_inode(inode
);
854 /* if on-disk stat data is of different length than required
855 for this inode, resize it */
857 if (data
.length
!= 0) {
861 assert("edward-1441",
862 !check_sd_resize(inode
, coord
,
863 data
.length
, 0/* before resize */));
865 /* insertion code requires that insertion point (coord) was
867 coord
->between
= AFTER_UNIT
;
868 result
= reiser4_resize_item(coord
, &data
, key
, lh
,
869 COPI_DONT_SHIFT_LEFT
);
871 key_warning(key
, inode
, result
);
875 if (loaded
!= coord
->node
) {
876 /* reiser4_resize_item moved coord to another node.
879 coord_clear_iplug(coord
);
880 result
= zload(coord
->node
);
883 loaded
= coord
->node
;
885 assert("edward-1442",
886 !check_sd_resize(inode
, coord
,
887 data
.length
, 1/* after resize */));
889 area
= item_body_by_coord(coord
);
890 spin_lock_inode(inode
);
891 result
= data
.iplug
->s
.sd
.save(inode
, &area
);
892 znode_make_dirty(coord
->node
);
894 /* re-initialise stat-data seal */
897 * coord.between was possibly skewed from AT_UNIT when stat-data size
898 * was changed and new extensions were pasted into item.
900 coord
->between
= AT_UNIT
;
901 reiser4_seal_init(&state
->sd_seal
, coord
, key
);
902 state
->sd_coord
= *coord
;
903 spin_unlock_inode(inode
);
904 check_inode_seal(inode
, coord
, key
);
909 /* Update existing stat-data in a tree. Called with inode state locked. Return
910 inode state locked. */
911 static int update_sd(struct inode
*inode
/* inode to update sd for */ )
918 assert("nikita-726", inode
!= NULL
);
920 /* no stat-data, nothing to update?! */
921 assert("nikita-3482", !reiser4_inode_get_flag(inode
, REISER4_NO_SD
));
925 result
= locate_inode_sd(inode
, &key
, &coord
, &lh
);
927 result
= update_sd_at(inode
, &coord
, &key
, &lh
);
933 /* helper for reiser4_delete_object_common and reiser4_delete_dir_common.
934 Remove object stat data. Space for that must be reserved by caller before
937 common_object_delete_no_reserve(struct inode
*inode
/* object to remove */ )
941 assert("nikita-1477", inode
!= NULL
);
943 if (!reiser4_inode_get_flag(inode
, REISER4_NO_SD
)) {
946 DQUOT_FREE_INODE(inode
);
949 build_sd_key(inode
, &sd_key
);
951 reiser4_cut_tree(reiser4_tree_by_inode(inode
),
952 &sd_key
, &sd_key
, NULL
, 0);
954 reiser4_inode_set_flag(inode
, REISER4_NO_SD
);
955 result
= oid_release(inode
->i_sb
, get_inode_oid(inode
));
957 oid_count_released();
959 result
= safe_link_del(reiser4_tree_by_inode(inode
),
960 get_inode_oid(inode
),
969 /* helper for safelink_common */
970 static int process_truncate(struct inode
*inode
, __u64 size
)
975 reiser4_context
*ctx
;
976 struct dentry dentry
;
978 assert("vs-21", is_in_reiser4_context());
979 ctx
= reiser4_init_context(inode
->i_sb
);
980 assert("vs-22", !IS_ERR(ctx
));
983 attr
.ia_valid
= ATTR_SIZE
| ATTR_CTIME
;
984 fplug
= inode_file_plugin(inode
);
986 mutex_lock(&inode
->i_mutex
);
987 assert("vs-1704", get_current_context()->trans
->atom
== NULL
);
988 dentry
.d_inode
= inode
;
989 result
= inode
->i_op
->setattr(&dentry
, &attr
);
990 mutex_unlock(&inode
->i_mutex
);
992 context_set_commit_async(ctx
);
993 reiser4_exit_context(ctx
);
1000 c-indentation-style: "K&R"