Blame view
fs/jfs/inode.c
9.94 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 |
/* * Copyright (C) International Business Machines Corp., 2000-2004 * Portions Copyright (C) Christoph Hellwig, 2001-2002 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by |
63f83c9fc JFS: White space ... |
7 |
* the Free Software Foundation; either version 2 of the License, or |
1da177e4c Linux-2.6.12-rc2 |
8 |
* (at your option) any later version. |
63f83c9fc JFS: White space ... |
9 |
* |
1da177e4c Linux-2.6.12-rc2 |
10 11 12 13 14 15 |
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License |
63f83c9fc JFS: White space ... |
16 |
* along with this program; if not, write to the Free Software |
1da177e4c Linux-2.6.12-rc2 |
17 18 19 20 21 22 23 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/fs.h> #include <linux/mpage.h> #include <linux/buffer_head.h> #include <linux/pagemap.h> #include <linux/quotaops.h> |
a9185b41a pass writeback_co... |
25 |
#include <linux/writeback.h> |
1da177e4c Linux-2.6.12-rc2 |
26 |
#include "jfs_incore.h" |
1868f4aa5 JFS: fix sparse w... |
27 |
#include "jfs_inode.h" |
1da177e4c Linux-2.6.12-rc2 |
28 29 30 31 32 |
#include "jfs_filsys.h" #include "jfs_imap.h" #include "jfs_extent.h" #include "jfs_unicode.h" #include "jfs_debug.h" |
eab1df71a iget: stop JFS fr... |
33 |
struct inode *jfs_iget(struct super_block *sb, unsigned long ino) |
1da177e4c Linux-2.6.12-rc2 |
34 |
{ |
eab1df71a iget: stop JFS fr... |
35 36 37 38 39 40 41 42 43 44 45 46 47 |
struct inode *inode; int ret; inode = iget_locked(sb, ino); if (!inode) return ERR_PTR(-ENOMEM); if (!(inode->i_state & I_NEW)) return inode; ret = diRead(inode); if (ret < 0) { iget_failed(inode); return ERR_PTR(ret); |
1da177e4c Linux-2.6.12-rc2 |
48 49 50 51 52 53 54 55 56 57 58 59 60 |
} if (S_ISREG(inode->i_mode)) { inode->i_op = &jfs_file_inode_operations; inode->i_fop = &jfs_file_operations; inode->i_mapping->a_ops = &jfs_aops; } else if (S_ISDIR(inode->i_mode)) { inode->i_op = &jfs_dir_inode_operations; inode->i_fop = &jfs_dir_operations; } else if (S_ISLNK(inode->i_mode)) { if (inode->i_size >= IDATASIZE) { inode->i_op = &page_symlink_inode_operations; inode->i_mapping->a_ops = &jfs_aops; |
d69e83d99 jfs: ensure symli... |
61 |
} else { |
c7f2e1f0a jfs: add jfs spec... |
62 |
inode->i_op = &jfs_fast_symlink_inode_operations; |
d69e83d99 jfs: ensure symli... |
63 64 65 66 67 68 |
/* * The inline data should be null-terminated, but * don't let on-disk corruption crash the kernel */ JFS_IP(inode)->i_inline[inode->i_size] = '\0'; } |
1da177e4c Linux-2.6.12-rc2 |
69 70 71 72 |
} else { inode->i_op = &jfs_file_inode_operations; init_special_inode(inode, inode->i_mode, inode->i_rdev); } |
eab1df71a iget: stop JFS fr... |
73 74 |
unlock_new_inode(inode); return inode; |
1da177e4c Linux-2.6.12-rc2 |
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
} /* * Workhorse of both fsync & write_inode */ int jfs_commit_inode(struct inode *inode, int wait) { int rc = 0; tid_t tid; static int noisy = 5; jfs_info("In jfs_commit_inode, inode = 0x%p", inode); /* * Don't commit if inode has been committed since last being * marked dirty, or if it has been deleted. */ if (inode->i_nlink == 0 || !test_cflag(COMMIT_Dirty, inode)) return 0; if (isReadOnly(inode)) { /* kernel allows writes to devices on read-only * partitions and may think inode is dirty */ if (!special_file(inode->i_mode) && noisy) { jfs_err("jfs_commit_inode(0x%p) called on " "read-only volume", inode); jfs_err("Is remount racy?"); noisy--; } return 0; } tid = txBegin(inode->i_sb, COMMIT_INODE); |
1de87444f JFS: semaphore to... |
109 |
mutex_lock(&JFS_IP(inode)->commit_mutex); |
1da177e4c Linux-2.6.12-rc2 |
110 111 |
/* |
1de87444f JFS: semaphore to... |
112 |
* Retest inode state after taking commit_mutex |
1da177e4c Linux-2.6.12-rc2 |
113 114 115 116 117 |
*/ if (inode->i_nlink && test_cflag(COMMIT_Dirty, inode)) rc = txCommit(tid, 1, &inode, wait ? COMMIT_SYNC : 0); txEnd(tid); |
1de87444f JFS: semaphore to... |
118 |
mutex_unlock(&JFS_IP(inode)->commit_mutex); |
1da177e4c Linux-2.6.12-rc2 |
119 120 |
return rc; } |
a9185b41a pass writeback_co... |
121 |
int jfs_write_inode(struct inode *inode, struct writeback_control *wbc) |
1da177e4c Linux-2.6.12-rc2 |
122 |
{ |
a9185b41a pass writeback_co... |
123 |
int wait = wbc->sync_mode == WB_SYNC_ALL; |
1da177e4c Linux-2.6.12-rc2 |
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
if (test_cflag(COMMIT_Nolink, inode)) return 0; /* * If COMMIT_DIRTY is not set, the inode isn't really dirty. * It has been committed since the last change, but was still * on the dirty inode list. */ if (!test_cflag(COMMIT_Dirty, inode)) { /* Make sure committed changes hit the disk */ jfs_flush_journal(JFS_SBI(inode->i_sb)->log, wait); return 0; } if (jfs_commit_inode(inode, wait)) { jfs_err("jfs_write_inode: jfs_commit_inode failed!"); return -EIO; } else return 0; } |
62aff86fd switch jfs to ->e... |
143 |
void jfs_evict_inode(struct inode *inode) |
1da177e4c Linux-2.6.12-rc2 |
144 |
{ |
62aff86fd switch jfs to ->e... |
145 |
jfs_info("In jfs_evict_inode, inode = 0x%p", inode); |
1da177e4c Linux-2.6.12-rc2 |
146 |
|
62aff86fd switch jfs to ->e... |
147 |
if (!inode->i_nlink && !is_bad_inode(inode)) { |
871a29315 dquot: cleanup dq... |
148 |
dquot_initialize(inode); |
907f4554e dquot: move dquot... |
149 |
|
62aff86fd switch jfs to ->e... |
150 151 |
if (JFS_IP(inode)->fileset == FILESYSTEM_I) { truncate_inode_pages(&inode->i_data, 0); |
fef266580 [PATCH] update fi... |
152 |
|
62aff86fd switch jfs to ->e... |
153 154 |
if (test_cflag(COMMIT_Freewmap, inode)) jfs_free_zero_link(inode); |
1da177e4c Linux-2.6.12-rc2 |
155 |
|
62aff86fd switch jfs to ->e... |
156 |
diFree(inode); |
1da177e4c Linux-2.6.12-rc2 |
157 |
|
62aff86fd switch jfs to ->e... |
158 159 160 161 162 163 164 165 |
/* * Free the inode from the quota allocation. */ dquot_initialize(inode); dquot_free_inode(inode); } } else { truncate_inode_pages(&inode->i_data, 0); |
b1b5d7f9b JFS: jfs_delete_i... |
166 |
} |
62aff86fd switch jfs to ->e... |
167 168 |
end_writeback(inode); dquot_drop(inode); |
1da177e4c Linux-2.6.12-rc2 |
169 |
} |
aa3857295 fs: pass exact ty... |
170 |
void jfs_dirty_inode(struct inode *inode, int flags) |
1da177e4c Linux-2.6.12-rc2 |
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
{ static int noisy = 5; if (isReadOnly(inode)) { if (!special_file(inode->i_mode) && noisy) { /* kernel allows writes to devices on read-only * partitions and may try to mark inode dirty */ jfs_err("jfs_dirty_inode called on read-only volume"); jfs_err("Is remount racy?"); noisy--; } return; } set_cflag(COMMIT_Dirty, inode); } |
115ff50ba JFS: Quota suppor... |
188 189 |
int jfs_get_block(struct inode *ip, sector_t lblock, struct buffer_head *bh_result, int create) |
1da177e4c Linux-2.6.12-rc2 |
190 191 192 |
{ s64 lblock64 = lblock; int rc = 0; |
1da177e4c Linux-2.6.12-rc2 |
193 194 195 |
xad_t xad; s64 xaddr; int xflag; |
115ff50ba JFS: Quota suppor... |
196 |
s32 xlen = bh_result->b_size >> ip->i_blkbits; |
1da177e4c Linux-2.6.12-rc2 |
197 198 |
/* |
1da177e4c Linux-2.6.12-rc2 |
199 200 |
* Take appropriate lock on inode */ |
7fab479be [PATCH] JFS: Supp... |
201 |
if (create) |
82d5b9a7c JFS: Add lockdep ... |
202 |
IWRITE_LOCK(ip, RDWRLOCK_NORMAL); |
7fab479be [PATCH] JFS: Supp... |
203 |
else |
82d5b9a7c JFS: Add lockdep ... |
204 |
IREAD_LOCK(ip, RDWRLOCK_NORMAL); |
1da177e4c Linux-2.6.12-rc2 |
205 206 |
if (((lblock64 << ip->i_sb->s_blocksize_bits) < ip->i_size) && |
115ff50ba JFS: Quota suppor... |
207 |
(!xtLookup(ip, lblock64, xlen, &xflag, &xaddr, &xlen, 0)) && |
6628465e3 [PATCH] JFS: Don'... |
208 |
xaddr) { |
1da177e4c Linux-2.6.12-rc2 |
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
if (xflag & XAD_NOTRECORDED) { if (!create) /* * Allocated but not recorded, read treats * this as a hole */ goto unlock; #ifdef _JFS_4K XADoffset(&xad, lblock64); XADlength(&xad, xlen); XADaddress(&xad, xaddr); #else /* _JFS_4K */ /* * As long as block size = 4K, this isn't a problem. * We should mark the whole page not ABNR, but how * will we know to mark the other blocks BH_New? */ BUG(); #endif /* _JFS_4K */ rc = extRecord(ip, &xad); if (rc) goto unlock; set_buffer_new(bh_result); } map_bh(bh_result, ip->i_sb, xaddr); bh_result->b_size = xlen << ip->i_blkbits; goto unlock; } if (!create) goto unlock; /* * Allocate a new block */ #ifdef _JFS_4K if ((rc = extHint(ip, lblock64 << ip->i_sb->s_blocksize_bits, &xad))) goto unlock; |
4d81715fc [PATCH] fs/jfs: C... |
247 |
rc = extAlloc(ip, xlen, lblock64, &xad, false); |
1da177e4c Linux-2.6.12-rc2 |
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
if (rc) goto unlock; set_buffer_new(bh_result); map_bh(bh_result, ip->i_sb, addressXAD(&xad)); bh_result->b_size = lengthXAD(&xad) << ip->i_blkbits; #else /* _JFS_4K */ /* * We need to do whatever it takes to keep all but the last buffers * in 4K pages - see jfs_write.c */ BUG(); #endif /* _JFS_4K */ unlock: /* * Release lock on inode */ |
7fab479be [PATCH] JFS: Supp... |
267 268 269 270 |
if (create) IWRITE_UNLOCK(ip); else IREAD_UNLOCK(ip); |
1da177e4c Linux-2.6.12-rc2 |
271 272 |
return rc; } |
1da177e4c Linux-2.6.12-rc2 |
273 274 |
static int jfs_writepage(struct page *page, struct writeback_control *wbc) { |
d5c5f84ba jfs: convert to n... |
275 |
return block_write_full_page(page, jfs_get_block, wbc); |
1da177e4c Linux-2.6.12-rc2 |
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
} static int jfs_writepages(struct address_space *mapping, struct writeback_control *wbc) { return mpage_writepages(mapping, wbc, jfs_get_block); } static int jfs_readpage(struct file *file, struct page *page) { return mpage_readpage(page, jfs_get_block); } static int jfs_readpages(struct file *file, struct address_space *mapping, struct list_head *pages, unsigned nr_pages) { return mpage_readpages(mapping, pages, nr_pages, jfs_get_block); } |
d5c5f84ba jfs: convert to n... |
294 295 296 |
static int jfs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata) |
1da177e4c Linux-2.6.12-rc2 |
297 |
{ |
ea0f04e59 get rid of nobh_w... |
298 299 300 |
int ret; ret = nobh_write_begin(mapping, pos, len, flags, pagep, fsdata, |
d5c5f84ba jfs: convert to n... |
301 |
jfs_get_block); |
ea0f04e59 get rid of nobh_w... |
302 303 304 305 306 307 308 |
if (unlikely(ret)) { loff_t isize = mapping->host->i_size; if (pos + len > isize) vmtruncate(mapping->host, isize); } return ret; |
1da177e4c Linux-2.6.12-rc2 |
309 310 311 312 313 314 315 316 317 318 319 320 |
} static sector_t jfs_bmap(struct address_space *mapping, sector_t block) { return generic_block_bmap(mapping, block, jfs_get_block); } static ssize_t jfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_t offset, unsigned long nr_segs) { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; |
eafdc7d19 sort out blockdev... |
321 |
ssize_t ret; |
1da177e4c Linux-2.6.12-rc2 |
322 |
|
aacfc19c6 fs: simplify the ... |
323 324 |
ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, jfs_get_block); |
eafdc7d19 sort out blockdev... |
325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
/* * In case of error extending write may have instantiated a few * blocks outside i_size. Trim these off again. */ if (unlikely((rw & WRITE) && ret < 0)) { loff_t isize = i_size_read(inode); loff_t end = offset + iov_length(iov, nr_segs); if (end > isize) vmtruncate(inode, isize); } return ret; |
1da177e4c Linux-2.6.12-rc2 |
339 |
} |
f5e54d6e5 [PATCH] mark addr... |
340 |
const struct address_space_operations jfs_aops = { |
1da177e4c Linux-2.6.12-rc2 |
341 342 343 344 |
.readpage = jfs_readpage, .readpages = jfs_readpages, .writepage = jfs_writepage, .writepages = jfs_writepages, |
d5c5f84ba jfs: convert to n... |
345 |
.write_begin = jfs_write_begin, |
03158cd7e fs: restore nobh |
346 |
.write_end = nobh_write_end, |
1da177e4c Linux-2.6.12-rc2 |
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
.bmap = jfs_bmap, .direct_IO = jfs_direct_IO, }; /* * Guts of jfs_truncate. Called with locks already held. Can be called * with directory for truncating directory index table. */ void jfs_truncate_nolock(struct inode *ip, loff_t length) { loff_t newsize; tid_t tid; ASSERT(length >= 0); if (test_cflag(COMMIT_Nolink, ip)) { xtTruncate(0, ip, length, COMMIT_WMAP); return; } do { tid = txBegin(ip->i_sb, 0); /* |
1de87444f JFS: semaphore to... |
371 |
* The commit_mutex cannot be taken before txBegin. |
1da177e4c Linux-2.6.12-rc2 |
372 373 374 375 |
* txBegin may block and there is a chance the inode * could be marked dirty and need to be committed * before txBegin unblocks */ |
1de87444f JFS: semaphore to... |
376 |
mutex_lock(&JFS_IP(ip)->commit_mutex); |
1da177e4c Linux-2.6.12-rc2 |
377 378 379 380 381 |
newsize = xtTruncate(tid, ip, length, COMMIT_TRUNCATE | COMMIT_PWMAP); if (newsize < 0) { txEnd(tid); |
1de87444f JFS: semaphore to... |
382 |
mutex_unlock(&JFS_IP(ip)->commit_mutex); |
1da177e4c Linux-2.6.12-rc2 |
383 384 385 386 387 388 389 390 |
break; } ip->i_mtime = ip->i_ctime = CURRENT_TIME; mark_inode_dirty(ip); txCommit(tid, 1, &ip, 0); txEnd(tid); |
1de87444f JFS: semaphore to... |
391 |
mutex_unlock(&JFS_IP(ip)->commit_mutex); |
1da177e4c Linux-2.6.12-rc2 |
392 393 394 395 396 397 |
} while (newsize > length); /* Truncate isn't always atomic */ } void jfs_truncate(struct inode *ip) { jfs_info("jfs_truncate: size = 0x%lx", (ulong) ip->i_size); |
03158cd7e fs: restore nobh |
398 |
nobh_truncate_page(ip->i_mapping, ip->i_size, jfs_get_block); |
1da177e4c Linux-2.6.12-rc2 |
399 |
|
82d5b9a7c JFS: Add lockdep ... |
400 |
IWRITE_LOCK(ip, RDWRLOCK_NORMAL); |
1da177e4c Linux-2.6.12-rc2 |
401 402 403 |
jfs_truncate_nolock(ip, ip->i_size); IWRITE_UNLOCK(ip); } |