Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-release-src > by-pkgid > 105d736c57b2691635bd047efe146ef0 > files > 1

btrfs-progs-0.20-0.rc1.20130117.2.mga3.src.rpm

From 8fe354744cd7b5c4f7a3314dcdbb5095192a032f Mon Sep 17 00:00:00 2001
From: Chris Mason <chris.mason@fusionio.com>
Date: Fri, 1 Feb 2013 10:44:22 -0500
Subject: [PATCH] Clear caches when opening and closing devices

This should fix problems with cache aliases in the kernel
---
 disk-io.c | 7 +++++++
 volumes.c | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/disk-io.c b/disk-io.c
index c4d4631..f00fe4e 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -641,6 +641,9 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 	if (sb_bytenr == 0)
 		sb_bytenr = BTRFS_SUPER_INFO_OFFSET;
 
+	/* try to drop all the caches */
+	posix_fadvise(fp, 0, 0, POSIX_FADV_DONTNEED);
+
 	ret = btrfs_scan_one_device(fp, path, &fs_devices,
 				    &total_devs, sb_bytenr);
 
@@ -1091,6 +1094,10 @@ static int close_all_devices(struct btrfs_fs_info *fs_info)
 	list = &fs_info->fs_devices->devices;
 	list_for_each(next, list) {
 		device = list_entry(next, struct btrfs_device, dev_list);
+		if (device->fd) {
+			fsync(device->fd);
+			posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED);
+		}
 		close(device->fd);
 	}
 	return 0;
diff --git a/volumes.c b/volumes.c
index 581c298..f3371b2 100644
--- a/volumes.c
+++ b/volumes.c
@@ -176,6 +176,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags)
 			goto fail;
 		}
 
+		posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
+
 		if (device->devid == fs_devices->latest_devid)
 			fs_devices->latest_bdev = fd;
 		if (device->devid == fs_devices->lowest_devid)
-- 
1.8.1.5