2 * inode.c - NILFS inode operations.
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Written by Ryusuke Konishi <ryusuke@osrg.net>
24 #include <linux/buffer_head.h>
25 #include <linux/mpage.h>
26 #include <linux/writeback.h>
27 #include <linux/uio.h>
37 * nilfs_get_block() - get a file block on the filesystem (callback function)
38 * @inode - inode struct of the target file
39 * @blkoff - file block number
40 * @bh_result - buffer head to be mapped on
41 * @create - indicate whether allocating the block or not when it has not
44 * This function does not issue actual read request of the specified data
45 * block. It is done by VFS.
46 * Bulk read for direct-io is not supported yet. (should be supported)
48 int nilfs_get_block(struct inode *inode, sector_t blkoff,
49 struct buffer_head *bh_result, int create)
51 struct nilfs_inode_info *ii = NILFS_I(inode);
52 unsigned long blknum = 0;
54 struct inode *dat = nilfs_dat_inode(NILFS_I_NILFS(inode));
56 /* This exclusion control is a workaround; should be revised */
57 down_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
58 ret = nilfs_bmap_lookup(ii->i_bmap, (unsigned long)blkoff, &blknum);
59 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
60 if (ret == 0) { /* found */
61 map_bh(bh_result, inode->i_sb, blknum);
64 if (unlikely(ret == 1)) {
65 printk(KERN_ERR "nilfs_get_block: bmap_lookup returns "
66 "buffer_head pointer (blkoff=%llu, blknum=%lu)\n",
67 (unsigned long long)blkoff, blknum);
70 /* data block was not found */
71 if (ret == -ENOENT && create) {
72 struct nilfs_transaction_info ti;
74 bh_result->b_blocknr = 0;
75 err = nilfs_transaction_begin(inode->i_sb, &ti, 1);
78 err = nilfs_bmap_insert(ii->i_bmap, (unsigned long)blkoff,
79 (unsigned long)bh_result);
80 if (unlikely(err != 0)) {
83 * The get_block() function could be called
84 * from multiple callers for an inode.
85 * However, the page having this block must
86 * be locked in this case.
89 "nilfs_get_block: a race condition "
90 "while inserting a data block. "
91 "(inode number=%lu, file block "
94 (unsigned long long)blkoff);
96 } else if (err == -EINVAL) {
97 nilfs_error(inode->i_sb, __func__,
98 "broken bmap (inode=%lu)\n",
102 nilfs_transaction_abort(inode->i_sb);
105 nilfs_transaction_commit(inode->i_sb); /* never fails */
106 /* Error handling should be detailed */
107 set_buffer_new(bh_result);
108 map_bh(bh_result, inode->i_sb, 0); /* dbn must be changed
110 } else if (ret == -ENOENT) {
111 /* not found is not error (e.g. hole); must return without
112 the mapped state flag. */
123 * nilfs_readpage() - implement readpage() method of nilfs_aops {}
124 * address_space_operations.
125 * @file - file struct of the file to be read
126 * @page - the page to be read
128 static int nilfs_readpage(struct file *file, struct page *page)
130 return mpage_readpage(page, nilfs_get_block);
134 * nilfs_readpages() - implement readpages() method of nilfs_aops {}
135 * address_space_operations.
136 * @file - file struct of the file to be read
137 * @mapping - address_space struct used for reading multiple pages
138 * @pages - the pages to be read
139 * @nr_pages - number of pages to be read
141 static int nilfs_readpages(struct file *file, struct address_space *mapping,
142 struct list_head *pages, unsigned nr_pages)
144 return mpage_readpages(mapping, pages, nr_pages, nilfs_get_block);
147 static int nilfs_writepages(struct address_space *mapping,
148 struct writeback_control *wbc)
150 struct inode *inode = mapping->host;
153 if (wbc->sync_mode == WB_SYNC_ALL)
154 err = nilfs_construct_dsync_segment(inode->i_sb, inode,
160 static int nilfs_writepage(struct page *page, struct writeback_control *wbc)
162 struct inode *inode = page->mapping->host;
165 redirty_page_for_writepage(wbc, page);
168 if (wbc->sync_mode == WB_SYNC_ALL) {
169 err = nilfs_construct_segment(inode->i_sb);
172 } else if (wbc->for_reclaim)
173 nilfs_flush_segment(inode->i_sb, inode->i_ino);
178 static int nilfs_set_page_dirty(struct page *page)
180 int ret = __set_page_dirty_buffers(page);
183 struct inode *inode = page->mapping->host;
184 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
185 unsigned nr_dirty = 1 << (PAGE_SHIFT - inode->i_blkbits);
187 nilfs_set_file_dirty(sbi, inode, nr_dirty);
192 static int nilfs_write_begin(struct file *file, struct address_space *mapping,
193 loff_t pos, unsigned len, unsigned flags,
194 struct page **pagep, void **fsdata)
197 struct inode *inode = mapping->host;
198 int err = nilfs_transaction_begin(inode->i_sb, NULL, 1);
204 err = block_write_begin(file, mapping, pos, len, flags, pagep,
205 fsdata, nilfs_get_block);
207 nilfs_transaction_abort(inode->i_sb);
211 static int nilfs_write_end(struct file *file, struct address_space *mapping,
212 loff_t pos, unsigned len, unsigned copied,
213 struct page *page, void *fsdata)
215 struct inode *inode = mapping->host;
216 unsigned start = pos & (PAGE_CACHE_SIZE - 1);
220 nr_dirty = nilfs_page_count_clean_buffers(page, start,
222 copied = generic_write_end(file, mapping, pos, len, copied, page,
224 nilfs_set_file_dirty(NILFS_SB(inode->i_sb), inode, nr_dirty);
225 err = nilfs_transaction_commit(inode->i_sb);
226 return err ? : copied;
230 nilfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
231 loff_t offset, unsigned long nr_segs)
233 struct file *file = iocb->ki_filp;
234 struct inode *inode = file->f_mapping->host;
240 /* Needs synchronization with the cleaner */
241 size = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
242 offset, nr_segs, nilfs_get_block, NULL);
246 struct address_space_operations nilfs_aops = {
247 .writepage = nilfs_writepage,
248 .readpage = nilfs_readpage,
249 /* .sync_page = nilfs_sync_page, */
250 .writepages = nilfs_writepages,
251 .set_page_dirty = nilfs_set_page_dirty,
252 .readpages = nilfs_readpages,
253 .write_begin = nilfs_write_begin,
254 .write_end = nilfs_write_end,
255 /* .releasepage = nilfs_releasepage, */
256 .invalidatepage = block_invalidatepage,
257 .direct_IO = nilfs_direct_IO,
260 struct inode *nilfs_new_inode(struct inode *dir, int mode)
262 struct super_block *sb = dir->i_sb;
263 struct nilfs_sb_info *sbi = NILFS_SB(sb);
265 struct nilfs_inode_info *ii;
269 inode = new_inode(sb);
270 if (unlikely(!inode))
273 mapping_set_gfp_mask(inode->i_mapping,
274 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
277 ii->i_state = 1 << NILFS_I_NEW;
279 err = nilfs_ifile_create_inode(sbi->s_ifile, &ino, &ii->i_bh);
281 goto failed_ifile_create_inode;
282 /* reference count of i_bh inherits from nilfs_mdt_read_block() */
284 atomic_inc(&sbi->s_inodes_count);
286 inode->i_uid = current_fsuid();
287 if (dir->i_mode & S_ISGID) {
288 inode->i_gid = dir->i_gid;
292 inode->i_gid = current_fsgid();
294 inode->i_mode = mode;
296 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
298 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
299 err = nilfs_bmap_read(ii->i_bmap, NULL);
303 set_bit(NILFS_I_BMAP, &ii->i_state);
304 /* No lock is needed; iget() ensures it. */
307 ii->i_flags = NILFS_I(dir)->i_flags;
309 ii->i_flags &= ~(NILFS_IMMUTABLE_FL | NILFS_APPEND_FL);
311 ii->i_flags &= ~NILFS_DIRSYNC_FL;
313 /* ii->i_file_acl = 0; */
314 /* ii->i_dir_acl = 0; */
316 ii->i_dir_start_lookup = 0;
317 #ifdef CONFIG_NILFS_FS_POSIX_ACL
319 ii->i_default_acl = NULL;
322 nilfs_set_inode_flags(inode);
323 spin_lock(&sbi->s_next_gen_lock);
324 inode->i_generation = sbi->s_next_generation++;
325 spin_unlock(&sbi->s_next_gen_lock);
326 insert_inode_hash(inode);
328 err = nilfs_init_acl(inode, dir);
330 goto failed_acl; /* never occur. When supporting
331 nilfs_init_acl(), proper cancellation of
332 above jobs should be considered */
334 mark_inode_dirty(inode);
340 iput(inode); /* raw_inode will be deleted through
341 generic_delete_inode() */
344 failed_ifile_create_inode:
345 make_bad_inode(inode);
346 iput(inode); /* if i_nlink == 1, generic_forget_inode() will be
352 void nilfs_free_inode(struct inode *inode)
354 struct super_block *sb = inode->i_sb;
355 struct nilfs_sb_info *sbi = NILFS_SB(sb);
358 /* XXX: check error code? Is there any thing I can do? */
359 (void) nilfs_ifile_delete_inode(sbi->s_ifile, inode->i_ino);
360 atomic_dec(&sbi->s_inodes_count);
363 void nilfs_set_inode_flags(struct inode *inode)
365 unsigned int flags = NILFS_I(inode)->i_flags;
367 inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
369 if (flags & NILFS_SYNC_FL)
370 inode->i_flags |= S_SYNC;
371 if (flags & NILFS_APPEND_FL)
372 inode->i_flags |= S_APPEND;
373 if (flags & NILFS_IMMUTABLE_FL)
374 inode->i_flags |= S_IMMUTABLE;
375 #ifndef NILFS_ATIME_DISABLE
376 if (flags & NILFS_NOATIME_FL)
378 inode->i_flags |= S_NOATIME;
379 if (flags & NILFS_DIRSYNC_FL)
380 inode->i_flags |= S_DIRSYNC;
381 mapping_set_gfp_mask(inode->i_mapping,
382 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
385 int nilfs_read_inode_common(struct inode *inode,
386 struct nilfs_inode *raw_inode)
388 struct nilfs_inode_info *ii = NILFS_I(inode);
391 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
392 inode->i_uid = (uid_t)le32_to_cpu(raw_inode->i_uid);
393 inode->i_gid = (gid_t)le32_to_cpu(raw_inode->i_gid);
394 inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
395 inode->i_size = le64_to_cpu(raw_inode->i_size);
396 inode->i_atime.tv_sec = le64_to_cpu(raw_inode->i_mtime);
397 inode->i_ctime.tv_sec = le64_to_cpu(raw_inode->i_ctime);
398 inode->i_mtime.tv_sec = le64_to_cpu(raw_inode->i_mtime);
399 inode->i_atime.tv_nsec = 0;
400 inode->i_ctime.tv_nsec = 0;
401 inode->i_mtime.tv_nsec = 0;
402 ii->i_dtime = le64_to_cpu(raw_inode->i_dtime);
403 if (inode->i_nlink == 0 && (inode->i_mode == 0 || ii->i_dtime))
404 return -EINVAL; /* this inode is deleted */
406 inode->i_blocks = le64_to_cpu(raw_inode->i_blocks);
407 ii->i_flags = le32_to_cpu(raw_inode->i_flags);
409 ii->i_file_acl = le32_to_cpu(raw_inode->i_file_acl);
410 ii->i_dir_acl = S_ISREG(inode->i_mode) ?
411 0 : le32_to_cpu(raw_inode->i_dir_acl);
414 inode->i_generation = le32_to_cpu(raw_inode->i_generation);
416 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
417 S_ISLNK(inode->i_mode)) {
418 err = nilfs_bmap_read(ii->i_bmap, raw_inode);
421 set_bit(NILFS_I_BMAP, &ii->i_state);
422 /* No lock is needed; iget() ensures it. */
427 static int nilfs_read_sketch_inode(struct inode *inode)
429 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
432 if (sbi->s_snapshot_cno) {
433 struct the_nilfs *nilfs = sbi->s_nilfs;
434 struct buffer_head *bh_cp;
435 struct nilfs_checkpoint *raw_cp;
437 err = nilfs_cpfile_get_checkpoint(
438 nilfs->ns_cpfile, sbi->s_snapshot_cno, 0, &raw_cp,
441 if (!nilfs_checkpoint_sketch(raw_cp))
443 nilfs_cpfile_put_checkpoint(
444 nilfs->ns_cpfile, sbi->s_snapshot_cno, bh_cp);
446 inode->i_flags |= S_NOCMTIME;
451 static int __nilfs_read_inode(struct super_block *sb, unsigned long ino,
454 struct nilfs_sb_info *sbi = NILFS_SB(sb);
455 struct inode *dat = nilfs_dat_inode(sbi->s_nilfs);
456 struct buffer_head *bh;
457 struct nilfs_inode *raw_inode;
460 down_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
461 err = nilfs_ifile_get_inode_block(sbi->s_ifile, ino, &bh);
465 raw_inode = nilfs_ifile_map_inode(sbi->s_ifile, ino, bh);
467 #ifdef CONFIG_NILFS_FS_POSIX_ACL
468 ii->i_acl = NILFS_ACL_NOT_CACHED;
469 ii->i_default_acl = NILFS_ACL_NOT_CACHED;
471 if (nilfs_read_inode_common(inode, raw_inode))
474 if (S_ISREG(inode->i_mode)) {
475 inode->i_op = &nilfs_file_inode_operations;
476 inode->i_fop = &nilfs_file_operations;
477 inode->i_mapping->a_ops = &nilfs_aops;
478 if (unlikely(inode->i_ino == NILFS_SKETCH_INO)) {
479 err = nilfs_read_sketch_inode(inode);
483 } else if (S_ISDIR(inode->i_mode)) {
484 inode->i_op = &nilfs_dir_inode_operations;
485 inode->i_fop = &nilfs_dir_operations;
486 inode->i_mapping->a_ops = &nilfs_aops;
487 } else if (S_ISLNK(inode->i_mode)) {
488 inode->i_op = &nilfs_symlink_inode_operations;
489 inode->i_mapping->a_ops = &nilfs_aops;
491 inode->i_op = &nilfs_special_inode_operations;
493 inode, inode->i_mode,
494 new_decode_dev(le64_to_cpu(raw_inode->i_device_code)));
496 nilfs_ifile_unmap_inode(sbi->s_ifile, ino, bh);
498 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
499 nilfs_set_inode_flags(inode);
503 nilfs_ifile_unmap_inode(sbi->s_ifile, ino, bh);
507 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
511 struct inode *nilfs_iget(struct super_block *sb, unsigned long ino)
516 inode = iget_locked(sb, ino);
517 if (unlikely(!inode))
518 return ERR_PTR(-ENOMEM);
519 if (!(inode->i_state & I_NEW))
522 err = __nilfs_read_inode(sb, ino, inode);
527 unlock_new_inode(inode);
531 void nilfs_write_inode_common(struct inode *inode,
532 struct nilfs_inode *raw_inode, int has_bmap)
534 struct nilfs_inode_info *ii = NILFS_I(inode);
536 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
537 raw_inode->i_uid = cpu_to_le32(inode->i_uid);
538 raw_inode->i_gid = cpu_to_le32(inode->i_gid);
539 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
540 raw_inode->i_size = cpu_to_le64(inode->i_size);
541 raw_inode->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
542 raw_inode->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec);
543 raw_inode->i_blocks = cpu_to_le64(inode->i_blocks);
545 raw_inode->i_dtime = cpu_to_le64(ii->i_dtime);
546 raw_inode->i_flags = cpu_to_le32(ii->i_flags);
547 raw_inode->i_generation = cpu_to_le32(inode->i_generation);
550 nilfs_bmap_write(ii->i_bmap, raw_inode);
551 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
552 raw_inode->i_device_code =
553 cpu_to_le64(new_encode_dev(inode->i_rdev));
554 /* When extending inode, nilfs->ns_inode_size should be checked
555 for substitutions of appended fields */
558 void nilfs_update_inode(struct inode *inode, struct buffer_head *ibh)
560 ino_t ino = inode->i_ino;
561 struct nilfs_inode_info *ii = NILFS_I(inode);
562 struct super_block *sb = inode->i_sb;
563 struct nilfs_sb_info *sbi = NILFS_SB(sb);
564 struct nilfs_inode *raw_inode;
566 raw_inode = nilfs_ifile_map_inode(sbi->s_ifile, ino, ibh);
568 /* The buffer is guarded with lock_buffer() by the caller */
569 if (test_and_clear_bit(NILFS_I_NEW, &ii->i_state))
570 memset(raw_inode, 0, NILFS_MDT(sbi->s_ifile)->mi_entry_size);
571 set_bit(NILFS_I_INODE_DIRTY, &ii->i_state);
573 nilfs_write_inode_common(inode, raw_inode, 0);
574 /* XXX: call with has_bmap = 0 is a workaround to avoid
575 deadlock of bmap. This delays update of i_bmap to just
577 nilfs_ifile_unmap_inode(sbi->s_ifile, ino, ibh);
580 #define NILFS_MAX_TRUNCATE_BLOCKS 16384 /* 64MB for 4KB block */
582 static void nilfs_truncate_bmap(struct nilfs_inode_info *ii,
588 if (!test_bit(NILFS_I_BMAP, &ii->i_state))
591 ret = nilfs_bmap_last_key(ii->i_bmap, &b);
600 b -= min_t(unsigned long, NILFS_MAX_TRUNCATE_BLOCKS, b - from);
601 ret = nilfs_bmap_truncate(ii->i_bmap, b);
602 nilfs_relax_pressure_in_lock(ii->vfs_inode.i_sb);
603 if (!ret || (ret == -ENOMEM &&
604 nilfs_bmap_truncate(ii->i_bmap, b) == 0))
609 nilfs_error(ii->vfs_inode.i_sb, __func__,
610 "bmap is broken (ino=%lu)", ii->vfs_inode.i_ino);
612 nilfs_warning(ii->vfs_inode.i_sb, __func__,
613 "failed to truncate bmap (ino=%lu, err=%d)",
614 ii->vfs_inode.i_ino, ret);
617 void nilfs_truncate(struct inode *inode)
619 unsigned long blkoff;
620 unsigned int blocksize;
621 struct nilfs_transaction_info ti;
622 struct super_block *sb = inode->i_sb;
623 struct nilfs_inode_info *ii = NILFS_I(inode);
626 if (!test_bit(NILFS_I_BMAP, &ii->i_state))
628 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
631 blocksize = sb->s_blocksize;
632 blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
633 ret = nilfs_transaction_begin(sb, &ti, 0);
636 block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
638 nilfs_truncate_bmap(ii, blkoff);
640 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
642 nilfs_set_transaction_flag(NILFS_TI_SYNC);
644 nilfs_set_file_dirty(NILFS_SB(sb), inode, 0);
645 nilfs_transaction_commit(sb);
646 /* May construct a logical segment and may fail in sync mode.
647 But truncate has no return value. */
650 void nilfs_delete_inode(struct inode *inode)
652 struct nilfs_transaction_info ti;
653 struct super_block *sb = inode->i_sb;
654 struct nilfs_inode_info *ii = NILFS_I(inode);
657 if (unlikely(is_bad_inode(inode))) {
658 if (inode->i_data.nrpages)
659 truncate_inode_pages(&inode->i_data, 0);
663 err = nilfs_transaction_begin(sb, &ti, 0);
665 if (inode->i_data.nrpages)
666 truncate_inode_pages(&inode->i_data, 0);
668 nilfs_truncate_bmap(ii, 0);
669 nilfs_free_inode(inode);
670 /* nilfs_free_inode() marks inode buffer dirty */
672 nilfs_set_transaction_flag(NILFS_TI_SYNC);
673 nilfs_transaction_commit(sb);
674 /* May construct a logical segment and may fail in sync mode.
675 But delete_inode has no return value. */
678 int nilfs_setattr(struct dentry *dentry, struct iattr *iattr)
680 struct nilfs_transaction_info ti;
681 struct inode *inode = dentry->d_inode;
682 struct super_block *sb = inode->i_sb;
685 err = inode_change_ok(inode, iattr);
689 err = nilfs_transaction_begin(sb, &ti, 0);
692 err = inode_setattr(inode, iattr);
693 if (!err && (iattr->ia_valid & ATTR_MODE))
694 err = nilfs_acl_chmod(inode);
696 err = nilfs_transaction_commit(sb);
698 nilfs_transaction_abort(sb);
703 int nilfs_load_inode_block(struct nilfs_sb_info *sbi, struct inode *inode,
704 struct buffer_head **pbh)
706 struct nilfs_inode_info *ii = NILFS_I(inode);
709 spin_lock(&sbi->s_inode_lock);
710 /* Caller of this function MUST lock s_inode_lock */
711 if (ii->i_bh == NULL) {
712 spin_unlock(&sbi->s_inode_lock);
713 err = nilfs_ifile_get_inode_block(sbi->s_ifile, inode->i_ino,
717 spin_lock(&sbi->s_inode_lock);
718 if (ii->i_bh == NULL)
728 spin_unlock(&sbi->s_inode_lock);
732 int nilfs_inode_dirty(struct inode *inode)
734 struct nilfs_inode_info *ii = NILFS_I(inode);
735 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
738 if (!list_empty(&ii->i_dirty)) {
739 spin_lock(&sbi->s_inode_lock);
740 ret = test_bit(NILFS_I_DIRTY, &ii->i_state) ||
741 test_bit(NILFS_I_BUSY, &ii->i_state);
742 spin_unlock(&sbi->s_inode_lock);
747 int nilfs_set_file_dirty(struct nilfs_sb_info *sbi, struct inode *inode,
750 struct nilfs_inode_info *ii = NILFS_I(inode);
752 atomic_add(nr_dirty, &sbi->s_nilfs->ns_ndirtyblks);
754 if (test_and_set_bit(NILFS_I_DIRTY, &ii->i_state) ||
755 unlikely(inode->i_ino == NILFS_SKETCH_INO))
758 spin_lock(&sbi->s_inode_lock);
759 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) &&
760 !test_bit(NILFS_I_BUSY, &ii->i_state)) {
761 /* Because this routine may race with nilfs_dispose_list(),
762 we have to check NILFS_I_QUEUED here, too. */
763 if (list_empty(&ii->i_dirty) && igrab(inode) == NULL) {
764 /* This will happen when somebody is freeing
766 nilfs_warning(sbi->s_super, __func__,
767 "cannot get inode (ino=%lu)\n",
769 spin_unlock(&sbi->s_inode_lock);
770 return -EINVAL; /* NILFS_I_DIRTY may remain for
773 list_del(&ii->i_dirty);
774 list_add_tail(&ii->i_dirty, &sbi->s_dirty_files);
775 set_bit(NILFS_I_QUEUED, &ii->i_state);
777 spin_unlock(&sbi->s_inode_lock);
781 int nilfs_mark_inode_dirty(struct inode *inode)
783 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
784 struct buffer_head *ibh;
787 err = nilfs_load_inode_block(sbi, inode, &ibh);
789 nilfs_warning(inode->i_sb, __func__,
790 "failed to reget inode block.\n");
794 nilfs_update_inode(inode, ibh);
796 nilfs_mdt_mark_buffer_dirty(ibh);
797 nilfs_mdt_mark_dirty(sbi->s_ifile);
803 * nilfs_dirty_inode - reflect changes on given inode to an inode block.
804 * @inode: inode of the file to be registered.
806 * nilfs_dirty_inode() loads a inode block containing the specified
807 * @inode and copies data from a nilfs_inode to a corresponding inode
808 * entry in the inode block. This operation is excluded from the segment
809 * construction. This function can be called both as a single operation
810 * and as a part of indivisible file operations.
812 void nilfs_dirty_inode(struct inode *inode)
814 struct nilfs_transaction_info ti;
816 if (is_bad_inode(inode)) {
817 nilfs_warning(inode->i_sb, __func__,
818 "tried to mark bad_inode dirty. ignored.\n");
822 nilfs_transaction_begin(inode->i_sb, &ti, 0);
823 if (likely(inode->i_ino != NILFS_SKETCH_INO))
824 nilfs_mark_inode_dirty(inode);
825 nilfs_transaction_commit(inode->i_sb); /* never fails */