2 * Copyright 2000 Hans Reiser
3 * See README for licensing and copyright details
5 * Ported to FreeBSD by Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
10 #include <gnu/fs/reiserfs/reiserfs_fs.h>
12 static b_strategy_t reiserfs_bufstrategy;
15 * Buffer operations for ReiserFS vnodes.
16 * We punt on VOP_BMAP, so we need to do strategy on the file's vnode
17 * rather than the underlying device's.
19 static struct buf_ops reiserfs_vnbufops = {
20 .bop_name = "ReiserFS",
21 .bop_strategy = reiserfs_bufstrategy,
24 /* Default io size devuned in super.c */
25 extern int reiserfs_default_io_size;
26 void inode_set_bytes(struct reiserfs_node *ip, off_t bytes);
28 /* Args for the create parameter of reiserfs_get_block */
29 #define GET_BLOCK_NO_CREATE 0 /* Don't create new blocks or convert
31 #define GET_BLOCK_CREATE 1 /* Add anything you need to find block */
32 #define GET_BLOCK_NO_HOLE 2 /* Return ENOENT for file holes */
33 #define GET_BLOCK_READ_DIRECT 4 /* Read the tail if indirect item not
35 #define GET_BLOCK_NO_ISEM 8 /* i_sem is not held, don't preallocate */
36 #define GET_BLOCK_NO_DANGLE 16 /* Don't leave any transactions running */
38 /* -------------------------------------------------------------------
40 * -------------------------------------------------------------------*/
43 reiserfs_read(struct vop_read_args *ap)
47 struct reiserfs_node *ip;
48 struct reiserfs_sb_info *sbi;
53 off_t bytesinfile, offset;
60 size = sbi->s_blocksize;
62 for (error = 0; uio->uio_resid > 0;) {
63 if ((bytesinfile = ip->i_size - uio->uio_offset) <= 0)
66 /* Compute the logical block number and its offset */
67 lbn = uio->uio_offset / size;
68 offset = uio->uio_offset % size;
69 reiserfs_log(LOG_DEBUG, "logical block number: %ju\n",
71 reiserfs_log(LOG_DEBUG, "block offset: %ju\n",
74 /* Read file blocks */
75 reiserfs_log(LOG_DEBUG, "reiserfs_get_block(%ju)\n",
77 if ((error = reiserfs_get_block(ip, lbn, offset, uio)) != 0) {
78 reiserfs_log(LOG_DEBUG,
79 "reiserfs_get_block returned the error %d\n",
89 reiserfs_bufstrategy(struct bufobj *bo, struct buf *bp)
95 KASSERT(bo == &vp->v_bufobj, ("BO/VP mismatch: vp %p bo %p != %p",
96 vp, &vp->v_bufobj, bo));
97 rc = VOP_STRATEGY(vp, bp);
98 KASSERT(rc == 0, ("ReiserFS VOP_STRATEGY failed: bp=%p, "
99 "vp=%p, rc=%d", bp, vp, rc));
103 reiserfs_inactive(struct vop_inactive_args *ap)
107 struct reiserfs_node *ip;
113 reiserfs_log(LOG_DEBUG, "deactivating inode used %d times\n",
117 /* Ignore inodes related to stale file handles. */
125 * If we are done with the inode, reclaim it so that it can be reused
128 if (ip->i_mode == 0) {
129 reiserfs_log(LOG_DEBUG, "recyling\n");
137 reiserfs_reclaim(struct vop_reclaim_args *ap)
139 struct reiserfs_node *ip;
144 reiserfs_log(LOG_DEBUG, "reclaiming inode used %d times\n",
148 /* XXX Update this node (write to the disk) */
150 /* Remove the inode from its hash chain. */
153 reiserfs_log(LOG_DEBUG, "free private data\n");
154 free(vp->v_data, M_REISERFSNODE);
156 vnode_destroy_vobject(vp);
161 /* -------------------------------------------------------------------
162 * Functions from linux/fs/reiserfs/inode.c
163 * -------------------------------------------------------------------*/
166 _make_cpu_key(struct cpu_key *key, int version,
167 uint32_t dirid, uint32_t objectid, off_t offset, int type, int length)
170 key->version = version;
172 key->on_disk_key.k_dir_id = dirid;
173 key->on_disk_key.k_objectid = objectid;
174 set_cpu_key_k_offset(key, offset);
175 set_cpu_key_k_type(key, type);
176 key->key_length = length;
180 * Take base of inode_key (it comes from inode always) (dirid, objectid)
181 * and version from an inode, set offset and type of key
184 make_cpu_key(struct cpu_key *key, struct reiserfs_node *ip, off_t offset,
185 int type, int length)
188 _make_cpu_key(key, get_inode_item_key_version(ip),
189 le32toh(INODE_PKEY(ip)->k_dir_id),
190 le32toh(INODE_PKEY(ip)->k_objectid),
191 offset, type, length);
195 reiserfs_get_block(struct reiserfs_node *ip, long block, off_t offset,
198 caddr_t blk = NULL, p;
200 /* unsigned long offset; */
201 INITIALIZE_PATH(path);
202 struct buf *bp, *blk_bp;
203 struct item_head *ih;
204 struct reiserfs_sb_info *sbi;
205 int blocknr, chars, done = 0, ret = 0, args = 0;
207 sbi = ip->i_reiserfs;
209 /* Prepare the key to look for the 'block'-th block of file */
210 reiserfs_log(LOG_DEBUG, "prepare cpu key\n");
211 make_cpu_key(&key, ip, (off_t)block * sbi->s_blocksize + 1, TYPE_ANY, 3);
214 reiserfs_log(LOG_DEBUG, "search for position\n");
215 if (search_for_position_by_key(sbi, &key, &path) != POSITION_FOUND) {
216 reiserfs_log(LOG_DEBUG, "position not found\n");
220 kunmap(bh_result->b_page);
223 * We do not return ENOENT if there is a hole but page is
224 * uptodate, because it means that there is some MMAPED data
225 * associated with it that is yet to be written to disk.
227 if ((args & GET_BLOCK_NO_HOLE)/* &&
228 !PageUptodate(bh_result->b_page)*/)
232 reiserfs_log(LOG_DEBUG, "position found\n");
234 bp = get_last_bp(&path);
237 if (is_indirect_le_ih(ih)) {
239 uint32_t *ind_item = (uint32_t *)B_I_PITEM(bp, ih);
241 reiserfs_log(LOG_DEBUG, "item is INDIRECT\n");
243 blocknr = get_block_num(ind_item, path.pos_in_item);
244 reiserfs_log(LOG_DEBUG, "block number: %d "
245 "(ind_item=%p, pos_in_item=%u)\n",
246 blocknr, ind_item, path.pos_in_item);
248 xfersize = MIN(sbi->s_blocksize - offset,
249 ip->i_size - uio->uio_offset);
250 xfersize = MIN(xfersize, uio->uio_resid);
253 ret = bread(sbi->s_devvp,
254 blocknr * btodb(sbi->s_blocksize),
255 sbi->s_blocksize, NOCRED, &blk_bp);
256 reiserfs_log(LOG_DEBUG, "xfersize: %ju\n",
258 ret = uiomove(blk_bp->b_data + offset, xfersize, uio);
262 * We do not return ENOENT if there is a hole but
263 * page is uptodate, because it means That there
264 * is some MMAPED data associated with it that
265 * is yet to be written to disk.
267 if ((args & GET_BLOCK_NO_HOLE)/* &&
268 !PageUptodate(bh_result->b_page)*/)
272 uio->uio_resid -= xfersize;
273 uio->uio_offset += xfersize;
280 reiserfs_log(LOG_DEBUG, "item should be DIRECT\n");
283 /* Requested data are in direct item(s) */
284 if (!(args & GET_BLOCK_READ_DIRECT)) {
286 * We are called by bmap. FIXME: we can not map block of
287 * file when it is stored in direct item(s)
292 kunmap(bh_result->b_page);
300 * If we've got a direct item, and the buffer or page was uptodate, we
301 * don't want to pull data off disk again. Skip to the end, where we
302 * map the buffer and return
304 if (buffer_uptodate(bh_result)) {
308 * grab_tail_page can trigger calls to reiserfs_get_block
309 * on up to date pages without any buffers. If the page
310 * is up to date, we don't want read old data off disk.
311 * Set the up to date bit on the buffer instead and jump
314 if (!bh_result->b_page || PageUptodate(bh_result->b_page)) {
315 set_buffer_uptodate(bh_result);
321 /* Read file tail into part of page */
322 offset = (cpu_key_k_offset(&key) - 1) & (PAGE_CACHE_SIZE - 1);
323 fs_gen = get_generation(ip->i_reiserfs);
324 copy_item_head(&tmp_ih, ih);
329 * We only want to kmap if we are reading the tail into the page. this
330 * is not the common case, so we don't kmap until we are sure we need
331 * to. But, this means the item might move if kmap schedules
334 blk = (char *)kmap(bh_result->b_page);
335 if (fs_changed (fs_gen, sbi) && item_moved(&tmp_ih, &path))
339 memset(blk, 0, sbi->s_blocksize);
342 reiserfs_log(LOG_DEBUG, "allocating buffer\n");
343 blk = malloc(ip->i_size, M_REISERFSNODE, M_WAITOK | M_ZERO);
351 if (!is_direct_le_ih(ih)) {
352 reiserfs_log(LOG_ERR, "BUG\n");
353 return (ENOENT); /* XXX Wrong error code */
357 * Make sure we don't read more bytes than actually exist
358 * in the file. This can happen in odd cases where i_size
359 * isn't correct, and when direct item padding results in
360 * a few extra bytes at the end of the direct item
362 if ((le_ih_k_offset(ih) + path.pos_in_item) > ip->i_size)
365 if ((le_ih_k_offset(ih) - 1 + ih_item_len(ih)) > ip->i_size) {
366 chars = ip->i_size - (le_ih_k_offset(ih) - 1) -
370 chars = ih_item_len(ih) - path.pos_in_item;
372 reiserfs_log(LOG_DEBUG, "copying %d bytes\n", chars);
373 memcpy(p, B_I_PITEM(bp, ih) + path.pos_in_item, chars);
375 reiserfs_log(LOG_DEBUG, "copy done\n");
381 if (PATH_LAST_POSITION(&path) != (B_NR_ITEMS(bp) - 1))
383 * We done, if read direct item is not the last
385 * FIXME: we could try to check right delimiting
386 * key to see whether direct item continues in
387 * the right neighbor or rely on i_size
391 /* Update key to look for the next piece */
392 set_cpu_key_k_offset(&key, cpu_key_k_offset(&key) + chars);
393 if (search_for_position_by_key(sbi, &key, &path) !=
396 * We read something from tail, even if now we got
401 bp = get_last_bp(&path);
408 * This buffer has valid data, but isn't valid for io. mapping it to
409 * block #0 tells the rest of reiserfs it just has a tail in it
411 ret = uiomove(blk, ip->i_size, uio);
412 free(blk, M_REISERFSNODE);
417 * Compute real number of used bytes by file
418 * Following three functions can go away when we'll have enough space in
422 real_space_diff(struct reiserfs_node *ip, int sd_size)
425 off_t blocksize = ip->i_reiserfs->s_blocksize;
427 if (S_ISLNK(ip->i_mode) || S_ISDIR(ip->i_mode))
430 /* End of file is also in full block with indirect reference, so round
431 * up to the next block.
433 * There is just no way to know if the tail is actually packed on the
434 * file, so we have to assume it isn't. When we pack the tail, we add
435 * 4 bytes to pretend there really is an unformatted node pointer. */
436 bytes = ((ip->i_size + (blocksize - 1)) >>
437 ip->i_reiserfs->s_blocksize_bits) * UNFM_P_SIZE + sd_size;
443 to_real_used_space(struct reiserfs_node *ip, unsigned long blocks, int sd_size)
446 if (S_ISLNK(ip->i_mode) || S_ISDIR(ip->i_mode)) {
447 return ip->i_size + (off_t)(real_space_diff(ip, sd_size));
450 return ((off_t)real_space_diff(ip, sd_size)) + (((off_t)blocks) << 9);
454 inode_set_bytes(struct reiserfs_node *ip, off_t bytes)
457 ip->i_blocks = bytes >> 9;
458 ip->i_bytes = bytes & 511;
461 /* Called by read_locked_inode */
463 init_inode(struct reiserfs_node *ip, struct path *path)
466 struct item_head *ih;
469 bp = PATH_PLAST_BUFFER(path);
470 ih = PATH_PITEM_HEAD(path);
472 reiserfs_log(LOG_DEBUG, "copy the key (objectid=%d, dirid=%d)\n",
473 ih->ih_key.k_objectid, ih->ih_key.k_dir_id);
474 copy_key(INODE_PKEY(ip), &(ih->ih_key));
475 /* ip->i_blksize = reiserfs_default_io_size; */
477 reiserfs_log(LOG_DEBUG, "reset some inode structure members\n");
478 REISERFS_I(ip)->i_flags = 0;
480 REISERFS_I(ip)->i_prealloc_block = 0;
481 REISERFS_I(ip)->i_prealloc_count = 0;
482 REISERFS_I(ip)->i_trans_id = 0;
483 REISERFS_I(ip)->i_jl = NULL;
484 REISERFS_I(ip)->i_acl_access = NULL;
485 REISERFS_I(ip)->i_acl_default = NULL;
488 if (stat_data_v1(ih)) {
489 reiserfs_log(LOG_DEBUG, "reiserfs/init_inode: stat data v1\n");
490 struct stat_data_v1 *sd;
491 unsigned long blocks;
493 sd = (struct stat_data_v1 *)B_I_PITEM(bp, ih);
495 reiserfs_log(LOG_DEBUG,
496 "reiserfs/init_inode: filling more members\n");
497 set_inode_item_key_version(ip, KEY_FORMAT_3_5);
498 set_inode_sd_version(ip, STAT_DATA_V1);
499 ip->i_mode = sd_v1_mode(sd);
500 ip->i_nlink = sd_v1_nlink(sd);
501 ip->i_uid = sd_v1_uid(sd);
502 ip->i_gid = sd_v1_gid(sd);
503 ip->i_size = sd_v1_size(sd);
504 ip->i_atime.tv_sec = sd_v1_atime(sd);
505 ip->i_mtime.tv_sec = sd_v1_mtime(sd);
506 ip->i_ctime.tv_sec = sd_v1_ctime(sd);
507 ip->i_atime.tv_nsec = 0;
508 ip->i_ctime.tv_nsec = 0;
509 ip->i_mtime.tv_nsec = 0;
511 reiserfs_log(LOG_DEBUG, " mode = %08x\n", ip->i_mode);
512 reiserfs_log(LOG_DEBUG, " nlink = %d\n", ip->i_nlink);
513 reiserfs_log(LOG_DEBUG, " owner = %d:%d\n", ip->i_uid,
515 reiserfs_log(LOG_DEBUG, " size = %ju\n",
516 (intmax_t)ip->i_size);
517 reiserfs_log(LOG_DEBUG, " atime = %jd\n",
518 (intmax_t)ip->i_atime.tv_sec);
519 reiserfs_log(LOG_DEBUG, " mtime = %jd\n",
520 (intmax_t)ip->i_mtime.tv_sec);
521 reiserfs_log(LOG_DEBUG, " ctime = %jd\n",
522 (intmax_t)ip->i_ctime.tv_sec);
524 ip->i_blocks = sd_v1_blocks(sd);
525 ip->i_generation = le32toh(INODE_PKEY(ip)->k_dir_id);
526 blocks = (ip->i_size + 511) >> 9;
527 blocks = _ROUND_UP(blocks, ip->i_reiserfs->s_blocksize >> 9);
528 if (ip->i_blocks > blocks) {
530 * There was a bug in <= 3.5.23 when i_blocks could
531 * take negative values. Starting from 3.5.17 this
532 * value could even be stored in stat data. For such
533 * files we set i_blocks based on file size. Just 2
534 * notes: this can be wrong for sparce files. On-disk
535 * value will be only updated if file's inode will
538 ip->i_blocks = blocks;
541 rdev = sd_v1_rdev(sd);
542 REISERFS_I(ip)->i_first_direct_byte =
543 sd_v1_first_direct_byte(sd);
546 * An early bug in the quota code can give us an odd number
547 * for the block count. This is incorrect, fix it here.
549 if (ip->i_blocks & 1) {
552 inode_set_bytes(ip, to_real_used_space(ip, ip->i_blocks,
556 * nopack is initially zero for v1 objects. For v2 objects,
557 * nopack is initialised from sd_attrs
559 REISERFS_I(ip)->i_flags &= ~i_nopack_mask;
560 reiserfs_log(LOG_DEBUG, "...done\n");
562 reiserfs_log(LOG_DEBUG, "stat data v2\n");
564 * New stat data found, but object may have old items
565 * (directories and symlinks)
567 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bp, ih);
569 reiserfs_log(LOG_DEBUG, "filling more members\n");
570 ip->i_mode = sd_v2_mode(sd);
571 ip->i_nlink = sd_v2_nlink(sd);
572 ip->i_uid = sd_v2_uid(sd);
573 ip->i_size = sd_v2_size(sd);
574 ip->i_gid = sd_v2_gid(sd);
575 ip->i_mtime.tv_sec = sd_v2_mtime(sd);
576 ip->i_atime.tv_sec = sd_v2_atime(sd);
577 ip->i_ctime.tv_sec = sd_v2_ctime(sd);
578 ip->i_ctime.tv_nsec = 0;
579 ip->i_mtime.tv_nsec = 0;
580 ip->i_atime.tv_nsec = 0;
582 reiserfs_log(LOG_DEBUG, " mode = %08x\n", ip->i_mode);
583 reiserfs_log(LOG_DEBUG, " nlink = %d\n", ip->i_nlink);
584 reiserfs_log(LOG_DEBUG, " owner = %d:%d\n", ip->i_uid,
586 reiserfs_log(LOG_DEBUG, " size = %ju\n",
587 (intmax_t)ip->i_size);
588 reiserfs_log(LOG_DEBUG, " atime = %jd\n",
589 (intmax_t)ip->i_atime.tv_sec);
590 reiserfs_log(LOG_DEBUG, " mtime = %jd\n",
591 (intmax_t)ip->i_mtime.tv_sec);
592 reiserfs_log(LOG_DEBUG, " ctime = %jd\n",
593 (intmax_t)ip->i_ctime.tv_sec);
595 ip->i_blocks = sd_v2_blocks(sd);
596 rdev = sd_v2_rdev(sd);
597 reiserfs_log(LOG_DEBUG, " blocks = %u\n", ip->i_blocks);
599 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode))
600 ip->i_generation = le32toh(INODE_PKEY(ip)->k_dir_id);
602 ip->i_generation = sd_v2_generation(sd);
604 if (S_ISDIR(ip->i_mode) || S_ISLNK(ip->i_mode))
605 set_inode_item_key_version(ip, KEY_FORMAT_3_5);
607 set_inode_item_key_version(ip, KEY_FORMAT_3_6);
609 REISERFS_I(ip)->i_first_direct_byte = 0;
610 set_inode_sd_version(ip, STAT_DATA_V2);
611 inode_set_bytes(ip, to_real_used_space(ip, ip->i_blocks,
615 * Read persistent inode attributes from sd and initalise
616 * generic inode flags from them
618 REISERFS_I(ip)->i_attrs = sd_v2_attrs(sd);
619 sd_attrs_to_i_attrs(sd_v2_attrs(sd), ip);
620 reiserfs_log(LOG_DEBUG, "...done\n");
624 if (S_ISREG(ip->i_mode)) {
625 reiserfs_log(LOG_DEBUG, "this inode is a regular file\n");
626 //ip->i_op = &reiserfs_file_ip_operations;
627 //ip->i_fop = &reiserfs_file_operations;
628 //ip->i_mapping->a_ops = &reiserfs_address_space_operations ;
629 } else if (S_ISDIR(ip->i_mode)) {
630 reiserfs_log(LOG_DEBUG, "this inode is a directory\n");
631 //ip->i_op = &reiserfs_dir_ip_operations;
632 //ip->i_fop = &reiserfs_dir_operations;
633 } else if (S_ISLNK(ip->i_mode)) {
634 reiserfs_log(LOG_DEBUG, "this inode is a symlink\n");
635 //ip->i_op = &reiserfs_symlink_ip_operations;
636 //ip->i_mapping->a_ops = &reiserfs_address_space_operations;
638 reiserfs_log(LOG_DEBUG, "this inode is something unknown in "
641 //ip->i_op = &reiserfs_special_ip_operations;
642 //init_special_ip(ip, ip->i_mode, new_decode_dev(rdev));
647 * reiserfs_read_locked_inode is called to read the inode off disk, and
648 * it does a make_bad_inode when things go wrong. But, we need to make
649 * sure and clear the key in the private portion of the inode, otherwise
650 * a corresponding iput might try to delete whatever object the inode
654 reiserfs_make_bad_inode(struct reiserfs_node *ip) {
656 memset(INODE_PKEY(ip), 0, KEY_SIZE);
657 //make_bad_inode(inode);
661 reiserfs_read_locked_inode(struct reiserfs_node *ip,
662 struct reiserfs_iget_args *args)
664 INITIALIZE_PATH(path_to_sd);
666 unsigned long dirino;
669 dirino = args->dirid;
672 * Set version 1, version 2 could be used too, because stat data
673 * key is the same in both versions
675 key.version = KEY_FORMAT_3_5;
676 key.on_disk_key.k_dir_id = dirino;
677 key.on_disk_key.k_objectid = ip->i_number;
678 key.on_disk_key.u.k_offset_v1.k_offset = SD_OFFSET;
679 key.on_disk_key.u.k_offset_v1.k_uniqueness = SD_UNIQUENESS;
681 /* Look for the object's stat data */
682 retval = search_item(ip->i_reiserfs, &key, &path_to_sd);
683 if (retval == IO_ERROR) {
684 reiserfs_log(LOG_ERR,
685 "I/O failure occured trying to find stat"
687 key.on_disk_key.k_dir_id, key.on_disk_key.k_objectid);
688 reiserfs_make_bad_inode(ip);
691 if (retval != ITEM_FOUND) {
693 * A stale NFS handle can trigger this without it being
696 reiserfs_log(LOG_ERR,
697 "item not found (objectid=%u, dirid=%u)\n",
698 key.on_disk_key.k_objectid, key.on_disk_key.k_dir_id);
699 pathrelse(&path_to_sd);
700 reiserfs_make_bad_inode(ip);
705 init_inode(ip, &path_to_sd);
708 * It is possible that knfsd is trying to access inode of a file
709 * that is being removed from the disk by some other thread. As
710 * we update sd on unlink all that is required is to check for
711 * nlink here. This bug was first found by Sizif when debugging
712 * SquidNG/Butterfly, forgotten, and found again after Philippe
713 * Gramoulle <philippe.gramoulle@mmania.com> reproduced it.
715 * More logical fix would require changes in fs/inode.c:iput() to
716 * remove inode from hash-table _after_ fs cleaned disk stuff up and
717 * in iget() to return NULL if I_FREEING inode is found in hash-table.
720 * Currently there is one place where it's ok to meet inode with
721 * nlink == 0: processing of open-unlinked and half-truncated files
722 * during mount (fs/reiserfs/super.c:finish_unfinished()).
724 if((ip->i_nlink == 0) &&
725 !REISERFS_SB(ip->i_reiserfs)->s_is_unlinked_ok ) {
726 reiserfs_log(LOG_WARNING, "dead inode read from disk. This is "
727 "likely to be race with knfsd. Ignore");
728 reiserfs_make_bad_inode(ip);
731 /* Init inode should be relsing */
732 reiserfs_check_path(&path_to_sd);
737 struct mount *mp, const struct cpu_key *key,
738 struct vnode **vpp, struct thread *td)
743 struct reiserfs_node *ip;
744 struct reiserfs_mount *rmp;
746 struct reiserfs_iget_args args;
749 /* Check if the inode cache contains it */
750 // XXX LK_EXCLUSIVE ?
751 flags = LK_EXCLUSIVE;
752 error = vfs_hash_get(mp, key->on_disk_key.k_objectid, flags,
753 td, vpp, NULL, NULL);
754 if (error || *vpp != NULL)
757 rmp = VFSTOREISERFS(mp);
760 reiserfs_log(LOG_DEBUG, "malloc(struct reiserfs_node)\n");
761 ip = malloc(sizeof(struct reiserfs_node), M_REISERFSNODE,
764 /* Allocate a new vnode/inode. */
765 reiserfs_log(LOG_DEBUG, "getnewvnode\n");
767 getnewvnode("reiserfs", mp, &reiserfs_vnodeops, &vp)) != 0) {
769 free(ip, M_REISERFSNODE);
770 reiserfs_log(LOG_DEBUG, "getnewvnode FAILED\n");
774 args.dirid = key->on_disk_key.k_dir_id;
775 args.objectid = key->on_disk_key.k_objectid;
777 reiserfs_log(LOG_DEBUG, "filling *ip\n");
781 ip->i_number = args.objectid;
782 ip->i_ino = args.dirid;
783 ip->i_reiserfs = rmp->rm_reiserfs;
785 vp->v_bufobj.bo_ops = &reiserfs_vnbufops;
786 vp->v_bufobj.bo_private = vp;
788 /* If this is the root node, set the VV_ROOT flag */
789 if (ip->i_number == REISERFS_ROOT_OBJECTID &&
790 ip->i_ino == REISERFS_ROOT_PARENT_OBJECTID)
791 vp->v_vflag |= VV_ROOT;
794 if (VOP_LOCK(vp, LK_EXCLUSIVE) != 0)
795 panic("reiserfs/iget: unexpected lock failure");
798 * Exclusively lock the vnode before adding to hash. Note, that we
799 * must not release nor downgrade the lock (despite flags argument
800 * says) till it is fully initialized.
802 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, (struct mtx *)0);
805 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
806 error = insmntque(vp, mp);
808 free(ip, M_REISERFSNODE);
810 reiserfs_log(LOG_DEBUG, "insmntque FAILED\n");
813 error = vfs_hash_insert(vp, key->on_disk_key.k_objectid, flags,
814 td, vpp, NULL, NULL);
815 if (error || *vpp != NULL)
819 reiserfs_log(LOG_DEBUG, "call reiserfs_read_locked_inode ("
820 "objectid=%d,dirid=%d)\n", args.objectid, args.dirid);
821 reiserfs_read_locked_inode(ip, &args);
823 ip->i_devvp = rmp->rm_devvp;
825 switch(vp->v_type = IFTOVT(ip->i_mode)) {
827 reiserfs_log(LOG_DEBUG, "vnode type VBLK\n");
828 vp->v_op = &reiserfs_specops;
832 reiserfs_log(LOG_DEBUG, "vnode type VCHR\n");
833 vp->v_op = &reiserfs_specops;
834 vp = addaliasu(vp, ip->i_rdev);
838 reiserfs_log(LOG_DEBUG, "vnode type VFIFO\n");
839 vp->v_op = reiserfs_fifoop_p;
851 sd_attrs_to_i_attrs(uint16_t sd_attrs, struct reiserfs_node *ip)
854 if (reiserfs_attrs(ip->i_reiserfs)) {
856 if (sd_attrs & REISERFS_SYNC_FL)
857 ip->i_flags |= S_SYNC;
859 ip->i_flags &= ~S_SYNC;
861 if (sd_attrs & REISERFS_IMMUTABLE_FL)
862 ip->i_flags |= IMMUTABLE;
864 ip->i_flags &= ~IMMUTABLE;
865 if (sd_attrs & REISERFS_APPEND_FL)
866 ip->i_flags |= APPEND;
868 ip->i_flags &= ~APPEND;
870 if (sd_attrs & REISERFS_NOATIME_FL)
871 ip->i_flags |= S_NOATIME;
873 ip->i_flags &= ~S_NOATIME;
874 if (sd_attrs & REISERFS_NOTAIL_FL)
875 REISERFS_I(ip)->i_flags |= i_nopack_mask;
877 REISERFS_I(ip)->i_flags &= ~i_nopack_mask;
883 i_attrs_to_sd_attrs(struct reiserfs_node *ip, uint16_t *sd_attrs)
886 if (reiserfs_attrs(ip->i_reiserfs)) {
888 if (ip->i_flags & S_SYNC)
889 *sd_attrs |= REISERFS_SYNC_FL;
891 *sd_attrs &= ~REISERFS_SYNC_FL;
893 if (ip->i_flags & IMMUTABLE)
894 *sd_attrs |= REISERFS_IMMUTABLE_FL;
896 *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
897 if (ip->i_flags & APPEND)
898 *sd_attrs |= REISERFS_APPEND_FL;
900 *sd_attrs &= ~REISERFS_APPEND_FL;
902 if (ip->i_flags & S_NOATIME)
903 *sd_attrs |= REISERFS_NOATIME_FL;
905 *sd_attrs &= ~REISERFS_NOATIME_FL;
906 if (REISERFS_I(ip)->i_flags & i_nopack_mask)
907 *sd_attrs |= REISERFS_NOTAIL_FL;
909 *sd_attrs &= ~REISERFS_NOTAIL_FL;