View | Details | Raw Unified | Return to bug 2645 | Differences between
and this patch

Collapse All | Expand All

(-)a/fs/buffer.c (+3 lines)
Lines 701-706 static int __set_page_dirty(struct page *page, Link Here
701
	if (unlikely(!mapping))
701
	if (unlikely(!mapping))
702
		return !TestSetPageDirty(page);
702
		return !TestSetPageDirty(page);
703
703
704
	mapping->mtime = CURRENT_TIME;
705
	set_bit(AS_MCTIME, &mapping->flags);
706
704
	if (TestSetPageDirty(page))
707
	if (TestSetPageDirty(page))
705
		return 0;
708
		return 0;
706
709
(-)a/fs/fs-writeback.c (+2 lines)
Lines 243-248 __sync_single_inode(struct inode *inode, struct writeback_control *wbc) Link Here
243
243
244
	spin_unlock(&inode_lock);
244
	spin_unlock(&inode_lock);
245
245
246
	mapping_update_time(mapping);
247
246
	ret = do_writepages(mapping, wbc);
248
	ret = do_writepages(mapping, wbc);
247
249
248
	/* Don't write the inode if only I_DIRTY_PAGES was set */
250
	/* Don't write the inode if only I_DIRTY_PAGES was set */
(-)a/fs/inode.c (-13 / +30 lines)
Lines 1243-1250 void touch_atime(struct vfsmount *mnt, struct dentry *dentry) Link Here
1243
EXPORT_SYMBOL(touch_atime);
1243
EXPORT_SYMBOL(touch_atime);
1244
1244
1245
/**
1245
/**
1246
 *	file_update_time	-	update mtime and ctime time
1246
 *	inode_update_time	-	update mtime and ctime time
1247
 *	@file: file accessed
1247
 *	@inode: inode accessed
1248
 *	@ts: time when inode was accessed
1249
 *	@sync: whether to do synchronous update
1248
 *
1250
 *
1249
 *	Update the mtime and ctime members of an inode and mark the inode
1251
 *	Update the mtime and ctime members of an inode and mark the inode
1250
 *	for writeback.  Note that this function is meant exclusively for
1252
 *	for writeback.  Note that this function is meant exclusively for
Lines 1253-1263 EXPORT_SYMBOL(touch_atime); Link Here
1253
 *	S_NOCTIME inode flag, e.g. for network filesystem where these
1255
 *	S_NOCTIME inode flag, e.g. for network filesystem where these
1254
 *	timestamps are handled by the server.
1256
 *	timestamps are handled by the server.
1255
 */
1257
 */
1256
1258
void inode_update_time(struct inode *inode, struct timespec *ts)
1257
void file_update_time(struct file *file)
1258
{
1259
{
1259
	struct inode *inode = file->f_path.dentry->d_inode;
1260
	struct timespec now;
1261
	int sync_it = 0;
1260
	int sync_it = 0;
1262
1261
1263
	if (IS_NOCMTIME(inode))
1262
	if (IS_NOCMTIME(inode))
Lines 1265-1286 void file_update_time(struct file *file) Link Here
1265
	if (IS_RDONLY(inode))
1264
	if (IS_RDONLY(inode))
1266
		return;
1265
		return;
1267
1266
1268
	now = current_fs_time(inode->i_sb);
1267
	if (timespec_compare(&inode->i_mtime, ts) < 0) {
1269
	if (!timespec_equal(&inode->i_mtime, &now)) {
1268
		inode->i_mtime = *ts;
1270
		inode->i_mtime = now;
1271
		sync_it = 1;
1269
		sync_it = 1;
1272
	}
1270
	}
1273
1271
1274
	if (!timespec_equal(&inode->i_ctime, &now)) {
1272
	if (timespec_compare(&inode->i_ctime, ts) < 0) {
1275
		inode->i_ctime = now;
1273
		inode->i_ctime = *ts;
1276
		sync_it = 1;
1274
		sync_it = 1;
1277
	}
1275
	}
1278
1276
1279
	if (sync_it)
1277
	if (sync_it)
1280
		mark_inode_dirty_sync(inode);
1278
		mark_inode_dirty_sync(inode);
1281
}
1279
}
1280
EXPORT_SYMBOL(inode_update_time);
1282
1281
1283
EXPORT_SYMBOL(file_update_time);
1282
/*
1283
 * Update the ctime and mtime stamps after checking if they are to be updated.
1284
 */
1285
void mapping_update_time(struct address_space *mapping)
1286
{
1287
	if (test_and_clear_bit(AS_MCTIME, &mapping->flags)) {
1288
		struct inode *inode = mapping->host;
1289
		struct timespec *ts = &mapping->mtime;
1290
1291
		if (S_ISBLK(inode->i_mode)) {
1292
			struct block_device *bdev = inode->i_bdev;
1293
1294
			mutex_lock(&bdev->bd_mutex);
1295
			list_for_each_entry(inode, &bdev->bd_inodes, i_devices)
1296
				inode_update_time(inode, ts);
1297
			mutex_unlock(&bdev->bd_mutex);
1298
		} else
1299
			inode_update_time(inode, ts);
1300
	}
1301
}
1284
1302
1285
int inode_needs_sync(struct inode *inode)
1303
int inode_needs_sync(struct inode *inode)
1286
{
1304
{
Lines 1290-1296 int inode_needs_sync(struct inode *inode) Link Here
1290
		return 1;
1308
		return 1;
1291
	return 0;
1309
	return 0;
1292
}
1310
}
1293
1294
EXPORT_SYMBOL(inode_needs_sync);
1311
EXPORT_SYMBOL(inode_needs_sync);
1295
1312
1296
int inode_wait(void *word)
1313
int inode_wait(void *word)
(-)a/fs/sync.c (+2 lines)
Lines 87-92 long do_fsync(struct file *file, int datasync) Link Here
87
		goto out;
87
		goto out;
88
	}
88
	}
89
89
90
	mapping_update_time(mapping);
91
90
	ret = filemap_fdatawrite(mapping);
92
	ret = filemap_fdatawrite(mapping);
91
93
92
	/*
94
	/*
(-)a/include/linux/fs.h (-1 / +12 lines)
Lines 511-516 struct address_space { Link Here
511
	spinlock_t		private_lock;	/* for use by the address_space */
511
	spinlock_t		private_lock;	/* for use by the address_space */
512
	struct list_head	private_list;	/* ditto */
512
	struct list_head	private_list;	/* ditto */
513
	struct address_space	*assoc_mapping;	/* ditto */
513
	struct address_space	*assoc_mapping;	/* ditto */
514
	struct timespec		mtime;		/* modification time */
514
} __attribute__((aligned(sizeof(long))));
515
} __attribute__((aligned(sizeof(long))));
515
	/*
516
	/*
516
	 * On most architectures that alignment is already the case; but
517
	 * On most architectures that alignment is already the case; but
Lines 1977-1983 extern int buffer_migrate_page(struct address_space *, Link Here
1977
extern int inode_change_ok(struct inode *, struct iattr *);
1978
extern int inode_change_ok(struct inode *, struct iattr *);
1978
extern int __must_check inode_setattr(struct inode *, struct iattr *);
1979
extern int __must_check inode_setattr(struct inode *, struct iattr *);
1979
1980
1980
extern void file_update_time(struct file *file);
1981
extern void inode_update_time(struct inode *, struct timespec *);
1982
1983
static inline void file_update_time(struct file *file)
1984
{
1985
	struct inode *inode = file->f_dentry->d_inode;
1986
	struct timespec ts = current_fs_time(inode->i_sb);
1987
1988
	inode_update_time(inode, &ts);
1989
}
1990
1991
extern void mapping_update_time(struct address_space *);
1981
1992
1982
static inline ino_t parent_ino(struct dentry *dentry)
1993
static inline ino_t parent_ino(struct dentry *dentry)
1983
{
1994
{
(-)a/include/linux/pagemap.h (-1 / +2 lines)
Lines 17-24 Link Here
17
 * Bits in mapping->flags.  The lower __GFP_BITS_SHIFT bits are the page
17
 * Bits in mapping->flags.  The lower __GFP_BITS_SHIFT bits are the page
18
 * allocation mode flags.
18
 * allocation mode flags.
19
 */
19
 */
20
#define	AS_EIO		(__GFP_BITS_SHIFT + 0)	/* IO error on async write */
20
#define AS_EIO		(__GFP_BITS_SHIFT + 0)	/* IO error on async write */
21
#define AS_ENOSPC	(__GFP_BITS_SHIFT + 1)	/* ENOSPC on async write */
21
#define AS_ENOSPC	(__GFP_BITS_SHIFT + 1)	/* ENOSPC on async write */
22
#define AS_MCTIME	(__GFP_BITS_SHIFT + 2)	/* mtime and ctime to update */
22
23
23
static inline void mapping_set_error(struct address_space *mapping, int error)
24
static inline void mapping_set_error(struct address_space *mapping, int error)
24
{
25
{
(-)a/mm/msync.c (-17 / +44 lines)
Lines 13-28 Link Here
13
#include <linux/syscalls.h>
13
#include <linux/syscalls.h>
14
14
15
/*
15
/*
16
 * Scan the PTEs for pages belonging to the VMA and mark them read-only.
17
 * It will force a pagefault on the next write access.
18
 */
19
static void vma_wrprotect(struct vm_area_struct *vma)
20
{
21
	unsigned long addr;
22
23
	for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) {
24
		spinlock_t *ptl;
25
		pgd_t *pgd = pgd_offset(vma->vm_mm, addr);
26
		pud_t *pud = pud_offset(pgd, addr);
27
		pmd_t *pmd = pmd_offset(pud, addr);
28
		pte_t *pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
29
30
		if (pte_dirty(*pte) && pte_write(*pte))
31
			*pte = pte_wrprotect(*pte);
32
		pte_unmap_unlock(pte, ptl);
33
	}
34
}
35
36
/*
16
 * MS_SYNC syncs the entire file - including mappings.
37
 * MS_SYNC syncs the entire file - including mappings.
17
 *
38
 *
18
 * MS_ASYNC does not start I/O (it used to, up to 2.5.67).
39
 * MS_ASYNC does not start I/O. Instead, it marks the relevant pages
19
 * Nor does it mark the relevant pages dirty (it used to up to 2.6.17).
40
 * read-only by calling vma_wrprotect(). This is needed to catch the next
20
 * Now it doesn't do anything, since dirty pages are properly tracked.
41
 * write reference to the mapped region and update the file times
42
 * accordingly.
21
 *
43
 *
22
 * The application may now run fsync() to
44
 * The application may now run fsync() to write out the dirty pages and
23
 * write out the dirty pages and wait on the writeout and check the result.
45
 * wait on the writeout and check the result. Or the application may run
24
 * Or the application may run fadvise(FADV_DONTNEED) against the fd to start
46
 * fadvise(FADV_DONTNEED) against the fd to start async writeout immediately.
25
 * async writeout immediately.
26
 * So by _not_ starting I/O in MS_ASYNC we provide complete flexibility to
47
 * So by _not_ starting I/O in MS_ASYNC we provide complete flexibility to
27
 * applications.
48
 * applications.
28
 */
49
 */
Lines 80-95 asmlinkage long sys_msync(unsigned long start, size_t len, int flags) Link Here
80
		start = vma->vm_end;
101
		start = vma->vm_end;
81
102
82
		file = vma->vm_file;
103
		file = vma->vm_file;
83
		if (file && (vma->vm_flags & VM_SHARED) && (flags & MS_SYNC)) {
104
		if (file && (vma->vm_flags & VM_SHARED)) {
84
			get_file(file);
105
			if (flags & MS_ASYNC) {
85
			up_read(&mm->mmap_sem);
106
				vma_wrprotect(vma);
86
			error = do_fsync(file, 0);
107
				mapping_update_time(file->f_mapping);
87
			fput(file);
108
			}
88
			if (error)
109
			if (flags & MS_SYNC) {
89
				goto out;
110
				get_file(file);
90
			down_read(&mm->mmap_sem);
111
				up_read(&mm->mmap_sem);
91
			vma = find_vma(mm, start);
112
				error = do_fsync(file, 0);
92
			continue;
113
				fput(file);
114
				if (error)
115
					goto out;
116
				down_read(&mm->mmap_sem);
117
				vma = find_vma(mm, start);
118
				continue;
119
			}
93
		}
120
		}
94
121
95
		vma = vma->vm_next;
122
		vma = vma->vm_next;
(-)a/mm/page-writeback.c (-26 / +29 lines)
Lines 997-1031 int __set_page_dirty_no_writeback(struct page *page) Link Here
997
 */
997
 */
998
int __set_page_dirty_nobuffers(struct page *page)
998
int __set_page_dirty_nobuffers(struct page *page)
999
{
999
{
1000
	if (!TestSetPageDirty(page)) {
1000
	struct address_space *mapping = page_mapping(page);
1001
		struct address_space *mapping = page_mapping(page);
1001
	struct address_space *mapping2;
1002
		struct address_space *mapping2;
1003
1002
1004
		if (!mapping)
1003
	if (!mapping)
1005
			return 1;
1004
		return 1;
1006
1005
1007
		write_lock_irq(&mapping->tree_lock);
1006
	mapping->mtime = CURRENT_TIME;
1008
		mapping2 = page_mapping(page);
1007
	set_bit(AS_MCTIME, &mapping->flags);
1009
		if (mapping2) { /* Race with truncate? */
1008
1010
			BUG_ON(mapping2 != mapping);
1009
	if (TestSetPageDirty(page))
1011
			WARN_ON_ONCE(!PagePrivate(page) && !PageUptodate(page));
1010
		return 0;
1012
			if (mapping_cap_account_dirty(mapping)) {
1011
1013
				__inc_zone_page_state(page, NR_FILE_DIRTY);
1012
	write_lock_irq(&mapping->tree_lock);
1014
				__inc_bdi_stat(mapping->backing_dev_info,
1013
	mapping2 = page_mapping(page);
1015
						BDI_RECLAIMABLE);
1014
	if (mapping2) {
1016
				task_io_account_write(PAGE_CACHE_SIZE);
1015
		/* Race with truncate? */
1017
			}
1016
		BUG_ON(mapping2 != mapping);
1018
			radix_tree_tag_set(&mapping->page_tree,
1017
		WARN_ON_ONCE(!PagePrivate(page) && !PageUptodate(page));
1019
				page_index(page), PAGECACHE_TAG_DIRTY);
1018
		if (mapping_cap_account_dirty(mapping)) {
1020
		}
1019
			__inc_zone_page_state(page, NR_FILE_DIRTY);
1021
		write_unlock_irq(&mapping->tree_lock);
1020
			__inc_bdi_stat(mapping->backing_dev_info,
1022
		if (mapping->host) {
1021
					BDI_RECLAIMABLE);
1023
			/* !PageAnon && !swapper_space */
1022
			task_io_account_write(PAGE_CACHE_SIZE);
1024
			__mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
1025
		}
1023
		}
1026
		return 1;
1024
		radix_tree_tag_set(&mapping->page_tree,
1025
				page_index(page), PAGECACHE_TAG_DIRTY);
1027
	}
1026
	}
1028
	return 0;
1027
	write_unlock_irq(&mapping->tree_lock);
1028
1029
	if (mapping->host)
1030
		__mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
1031
1032
	return 1;
1029
}
1033
}
1030
EXPORT_SYMBOL(__set_page_dirty_nobuffers);
1034
EXPORT_SYMBOL(__set_page_dirty_nobuffers);
1031
1035
1032
- 

Return to bug 2645