Permalink
Browse files

Merge pull request #20 from unit3/master

Pull in DKMS/autoload/initramfs support.
  • Loading branch information...
2 parents 05ff5cf + a521f5e commit e6c43fcedb62c29cd25c105fac1e8381814d4a4e @mohans mohans committed Sep 19, 2011
View
@@ -0,0 +1,44 @@
+COMMIT_REV := $(shell git describe --always --abbrev=12)
+DKMS_DEST ?= /var/lib/dkms/flashcache/$(COMMIT_REV)/source
+# statically link for inclusion in initramfs
+CFLAGS += -static
+export COMMIT_REV CFLAGS
+
+UTILS := /sbin/flashcache_load /sbin/flashcache_create /sbin/flashcache_destroy
+
+.PHONY: all
+all: install
+
+.PHONY: install
+install: build $(UTILS)
+ dkms install -m flashcache -v $(COMMIT_REV)
+
+.PHONY: build
+build: src_install
+ dkms build -m flashcache -v $(COMMIT_REV)
+
+.PHONY: src_install
+src_install:
+ install -o root -g root -m 0755 -d $(DKMS_DEST)
+ rsync -r src/ $(DKMS_DEST)/
+ sed "s/PACKAGE_VERSION=/PACKAGE_VERSION=$(COMMIT_REV)/" src/dkms.conf > "$(DKMS_DEST)/dkms.conf"
+
+.PHONY: boot_conf
+boot_conf: utils
+ # do mkinitramfs install if present
+ if test -d /etc/initramfs-tools/hooks; then \
+ install -o root -g root src/flashcache.hook /etc/initramfs-tools/hooks/flashcache ; \
+ install -o root -g root src/utils/flashcache_scan /etc/initramfs-tools/scripts/init-premount/ ; \
+ update-initramfs -k $(shell uname -r) -u ; \
+ fi
+
+.PHONY: utils
+utils:
+ $(MAKE) -C src/utils install
+
+.PHONY: clean
+clean:
+ $(MAKE) -f Makefile clean
+ dkms remove -m flashcache -v $(COMMIT_REV) --all
+ rm /etc/initramfs-tools/hooks/flashcache
+ rm /etc/initramfs-tools/scripts/init-premount/flashcache_scan
View
@@ -7,28 +7,39 @@ and maintaining additional third party kernel modules.
http://en.wikipedia.org/wiki/Dynamic_Kernel_Module_Support
I've added some simple DKMS configs for flashcache to make building and managing it a little less painful.
-The dirt quick way to get this working on Ubuntu 10.04 is as follows, and should be similar for any other
-distro supporting DKMS:
-
-1. Symlink the flashcache and/or flashcache-wt source directories into /usr/src so DKMS can find them:
-
- cd /usr/src
- sudo ln -s /path/to/flashcache/src flashcache-0.1
- sudo ln -s /path/to/flashcache-wt/src flashcache-0.1
-
-2. Add them to DKMS:
-
- sudo dkms add -m flashcache -v 0.1
- sudo dkms add -m flashcache-wt -v 0.1
-
-3. Build and install the modules using DKMS:
-
- sudo dkms build -m flashcache -v 0.1 && sudo dkms install -m flashcache -v 0.1
- sudo dkms build -m flashcache-wt -v 0.1 && sudo dkms install -m flashcache-wt -v 0.1
-
-Done!
-
-Note that this won't install the utils you need to create the flashcache devices, you still
-have to build and install those separately.
-
- - Graeme Humphries <graeme@sudo.ca>
+This has been updated with a Makefile.dkms, which should hopefully do a sensible DKMS install without
+intervention. It's only been tested on Ubuntu 11.04, and right now requires initramfs-tools for boot support,
+so it probably won't work on CentOS 5 just yet. I plan to test and update things for CentOS 5 and 6
+in the near future.
+
+Installation
+------------
+
+Run "make -f Makefile.dkms", and it should build and install correctly for your kernel.
+
+Boot from Flashcache
+--------------------
+If you have initramfs-tools, then flashcache utils and modules can be installed into the initramfs.
+
+Ubuntu:
+ - Install flashcache modules and utilities using instructions from "Installation" section above.
+ - Install flashcache boot support:
+ make -f Makefile.dkms boot_conf
+ - Edit your /etc/fstab and /boot/grub/grub.cfg to change the root device to the flashcache device you intend to use.
+ (ex: /dev/mapper/fc-root)
+ - Boot off a live CD like the Ubuntu desktop installer.
+ - Mount your root device (mount /dev/root-partition /mnt)
+ - cd to your flashcache source directory, and install flashcache into the boot environment. (make install)
+ - Unmount your root device (umount /mnt)
+ - Create flashcache device backed by your root device. I recommend using the UUID path in case device renaming occurs:
+ flashcache_create -p back fc-root /dev/ssd_device /dev/disk/by-uuid/root_device_uuid
+ - Reboot!
+
+CentOS:
+ - Instructions forthcoming once I've tested it. ;)
+
+Known Issues:
+ - Right now grub-probe fails to detect the underlying root device when booting off flashcache,
+ so you'll have to edit /boot/grub/grub.cfg manually.
+
+Graeme Humphries <graeme@sudo.ca>
@@ -53,12 +53,15 @@ sectors instead. The name of the device created is "cachedev".
flashcache_load : Load an existing writeback cache volume.
-flashcache_load cachedevname ssd_devname disk_devname
+flashcache_load ssd_devname [cachedev_name]
Example :
-flashcache_load cachedev /dev/sdc /dev/sdb
-Load the existing writeback cache on /dev/sdc, calling the flashcache volume
-cachedev.
+flashcache_load /dev/sd
+Load the existing writeback cache on /dev/sdc, using the virtual
+cachedev_name from when the device was created. If you're upgrading from
+an older flashcache device format that didn't store the cachedev name
+internally, or you want to change the cachedev name use, you can specify
+it as an optional second argument to flashcache_load.
flashcache_destroy : Destroy an existing flashcache. All data will be lost !!!
@@ -256,7 +259,7 @@ table_file : other cache args (format below). If this is omitted, dmsetup
attempts to read this from stdin.
table_file format :
-0 <disk dev sz in sectors> flashcache <disk dev> <ssd dev> <cache mode> <flashcache cmd> <blksize in sectors> [size of cache in sectors] [cache set size]
+0 <disk dev sz in sectors> flashcache <disk dev> <ssd dev> <dm virtual name> <cache mode> <flashcache cmd> <blksize in sectors> [size of cache in sectors] [cache set size]
cache mode:
1: Write Back
@@ -286,7 +289,7 @@ cache set size:
Example :
-echo 0 `blockdev --getsize /dev/cciss/c0d1p2` flashcache /dev/cciss/c0d1p2 /dev/fioa2 1 2 8 522000000 | dmsetup create cachedev
+echo 0 `blockdev --getsize /dev/cciss/c0d1p2` flashcache /dev/cciss/c0d1p2 /dev/fioa2 cachedev 1 2 8 522000000 | dmsetup create cachedev
This creates a writeback cache device called "cachedev" (/dev/mapper/cachedev)
with a 4KB blocksize to cache /dev/cciss/c0d1p2 on /dev/fioa2.
View
@@ -1,7 +1,7 @@
BUILT_MODULE_NAME=flashcache
DEST_MODULE_LOCATION=/kernel/drivers/block
PACKAGE_NAME=flashcache
-PACKAGE_VERSION=0.1
+PACKAGE_VERSION=
AUTOINSTALL=yes
REMAKE_INITRD=yes
-MAKE[0]="KERNEL_TREE=$kernel_source_dir make"
+MAKE="KERNEL_TREE=$kernel_source_dir make modules"
View
@@ -254,6 +254,9 @@ struct cache_c {
void *sysctl_handle;
+ // DM virtual device name, stored in superblock and restored on load
+ char dm_vdevname[DEV_PATHLEN];
+ // real device names are now stored as UUIDs
char cache_devname[DEV_PATHLEN];
char disk_devname[DEV_PATHLEN];
@@ -358,9 +361,9 @@ struct flash_superblock {
u_int32_t block_size; /* Cache block size */
u_int32_t assoc; /* Cache associativity */
u_int32_t cache_sb_state; /* Clean shutdown ? */
- char cache_devname[DEV_PATHLEN];
+ char cache_devname[DEV_PATHLEN]; /* Contains dm_vdev name as of v2 modifications */
sector_t cache_devsize;
- char disk_devname[DEV_PATHLEN];
+ char disk_devname[DEV_PATHLEN]; /* underlying block device name (use UUID paths!) */
sector_t disk_devsize;
u_int32_t cache_version;
u_int32_t md_block_size;
View
@@ -0,0 +1,24 @@
+#!/bin/sh -e
+# mkinitramfs hook for flashcache
+
+PREREQ="mdadm"
+
+prereqs () {
+ echo "$PREREQ"
+}
+
+case $1 in
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /usr/share/initramfs-tools/hook-functions
+
+manual_add_modules flashcache
+copy_exec /sbin/flashcache_load /sbin
+copy_exec /sbin/flashcache_create /sbin
+copy_exec /sbin/flashcache_destroy /sbin
+
+exit 0
View
@@ -305,11 +305,11 @@ flashcache_writeback_md_store(struct cache_c *dmc)
header->size = dmc->size;
header->assoc = dmc->assoc;
strncpy(header->disk_devname, dmc->disk_devname, DEV_PATHLEN);
- strncpy(header->cache_devname, dmc->cache_devname, DEV_PATHLEN);
+ strncpy(header->cache_devname, dmc->dm_vdevname, DEV_PATHLEN);
header->cache_devsize = to_sector(dmc->cache_dev->bdev->bd_inode->i_size);
header->disk_devsize = to_sector(dmc->disk_dev->bdev->bd_inode->i_size);
header->cache_version = dmc->on_ssd_version;
-
+
DPRINTK("Store metadata to disk: block size(%u), md block size(%u), cache size(%llu)" \
"associativity(%u)",
header->block_size, header->md_block_size, header->size,
@@ -569,12 +569,16 @@ flashcache_writeback_create(struct cache_c *dmc, int force)
header->size = dmc->size;
header->assoc = dmc->assoc;
strncpy(header->disk_devname, dmc->disk_devname, DEV_PATHLEN);
- strncpy(header->cache_devname, dmc->cache_devname, DEV_PATHLEN);
+ strncpy(header->cache_devname, dmc->dm_vdevname, DEV_PATHLEN);
header->cache_devsize = to_sector(dmc->cache_dev->bdev->bd_inode->i_size);
header->disk_devsize = to_sector(dmc->disk_dev->bdev->bd_inode->i_size);
dmc->on_ssd_version = header->cache_version = FLASHCACHE_VERSION;
where.sector = 0;
where.count = dmc->md_block_size;
+
+ printk("flashcache-dbg: cachedev check - %s %s", header->cache_devname,
+ dmc->dm_vdevname);
+
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
error = flashcache_dm_io_sync_vm(dmc, &where, WRITE, header);
#else
@@ -807,7 +811,7 @@ flashcache_writeback_load(struct cache_c *dmc)
header->assoc = dmc->assoc;
header->cache_sb_state = CACHE_MD_STATE_DIRTY;
strncpy(header->disk_devname, dmc->disk_devname, DEV_PATHLEN);
- strncpy(header->cache_devname, dmc->cache_devname, DEV_PATHLEN);
+ strncpy(header->cache_devname, dmc->dm_vdevname, DEV_PATHLEN);
header->cache_devsize = to_sector(dmc->cache_dev->bdev->bd_inode->i_size);
header->disk_devsize = to_sector(dmc->disk_dev->bdev->bd_inode->i_size);
header->cache_version = dmc->on_ssd_version;
@@ -876,11 +880,14 @@ flashcache_get_dev(struct dm_target *ti, char *pth, struct dm_dev **dmd,
* Construct a cache mapping.
* arg[0]: path to source device
* arg[1]: path to cache device
- * arg[2]: cache persistence (if set, cache conf is loaded from disk)
+ * arg[2]: md virtual device name
+ * arg[3]: cache mode (from flashcache.h)
+ * arg[4]: cache persistence (if set, cache conf is loaded from disk)
* Cache configuration parameters (if not set, default values are used.
- * arg[3]: cache block size (in sectors)
- * arg[4]: cache size (in blocks)
- * arg[5]: cache associativity
+ * arg[5]: cache block size (in sectors)
+ * arg[6]: cache size (in blocks)
+ * arg[7]: cache associativity
+ * arg[8]: md block size (in sectors)
*/
int
flashcache_ctr(struct dm_target *ti, unsigned int argc, char **argv)
@@ -914,13 +921,18 @@ flashcache_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto bad2;
}
+ if (sscanf(argv[2], "%s", &dmc->dm_vdevname) != 1) {
+ ti->error = "flashcache: Virtual device name lookup failed";
+ goto bad3;
+ }
+
r = flashcache_kcached_init(dmc);
if (r) {
ti->error = "Failed to initialize kcached";
goto bad3;
}
- if (sscanf(argv[2], "%u", &dmc->cache_mode) != 1) {
+ if (sscanf(argv[3], "%u", &dmc->cache_mode) != 1) {
ti->error = "flashcache: sscanf failed, invalid cache mode";
r = -EINVAL;
goto bad3;
@@ -938,8 +950,8 @@ flashcache_ctr(struct dm_target *ti, unsigned int argc, char **argv)
* Maybe this should really be moved to the end of the param list ?
*/
if (dmc->cache_mode == FLASHCACHE_WRITE_BACK) {
- if (argc >= 4) {
- if (sscanf(argv[3], "%u", &persistence) != 1) {
+ if (argc >= 5) {
+ if (sscanf(argv[4], "%u", &persistence) != 1) {
ti->error = "flashcache: sscanf failed, invalid cache persistence";
r = -EINVAL;
goto bad3;
@@ -962,8 +974,8 @@ flashcache_ctr(struct dm_target *ti, unsigned int argc, char **argv)
} else
persistence = CACHE_CREATE;
- if (argc >= 5) {
- if (sscanf(argv[4], "%u", &dmc->block_size) != 1) {
+ if (argc >= 6) {
+ if (sscanf(argv[5], "%u", &dmc->block_size) != 1) {
ti->error = "flashcache: Invalid block size";
r = -EINVAL;
goto bad3;
@@ -981,8 +993,8 @@ flashcache_ctr(struct dm_target *ti, unsigned int argc, char **argv)
dmc->block_mask = dmc->block_size - 1;
/* dmc->size is specified in sectors here, and converted to blocks later */
- if (argc >= 6) {
- if (sscanf(argv[5], "%lu", &dmc->size) != 1) {
+ if (argc >= 7) {
+ if (sscanf(argv[6], "%lu", &dmc->size) != 1) {
ti->error = "flashcache: Invalid cache size";
r = -EINVAL;
goto bad3;
@@ -992,8 +1004,8 @@ flashcache_ctr(struct dm_target *ti, unsigned int argc, char **argv)
if (!dmc->size)
dmc->size = to_sector(dmc->cache_dev->bdev->bd_inode->i_size);
- if (argc >= 7) {
- if (sscanf(argv[6], "%u", &dmc->assoc) != 1) {
+ if (argc >= 8) {
+ if (sscanf(argv[7], "%u", &dmc->assoc) != 1) {
ti->error = "flashcache: Invalid cache associativity";
r = -EINVAL;
goto bad3;
@@ -1013,8 +1025,8 @@ flashcache_ctr(struct dm_target *ti, unsigned int argc, char **argv)
dmc->assoc_shift = ffs(dmc->assoc) - 1;
if (dmc->cache_mode == FLASHCACHE_WRITE_BACK) {
- if (argc >= 8) {
- if (sscanf(argv[7], "%u", &dmc->md_block_size) != 1) {
+ if (argc >= 9) {
+ if (sscanf(argv[8], "%u", &dmc->md_block_size) != 1) {
ti->error = "flashcache: Invalid metadata block size";
r = -EINVAL;
goto bad3;
@@ -1353,11 +1365,11 @@ flashcache_dtr_stats_print(struct cache_c *dmc)
else
cache_mode = "WRITE_AROUND";
DMINFO("conf:\n" \
- "\tssd dev (%s), disk dev (%s) cache mode(%s)\n" \
+ "\tvirt dev (%s), ssd dev (%s), disk dev (%s) cache mode(%s)\n" \
"\tcapacity(%luM), associativity(%u), data block size(%uK) metadata block size(%ub)\n" \
"\ttotal blocks(%lu), cached blocks(%lu), cache percent(%d)\n" \
"\tdirty blocks(%d), dirty percent(%d)\n",
- dmc->cache_devname, dmc->disk_devname,
+ dmc->dm_vdevname, dmc->cache_devname, dmc->disk_devname,
cache_mode,
dmc->size*dmc->block_size>>11, dmc->assoc,
dmc->block_size>>(10-SECTOR_SHIFT),
@@ -1674,7 +1686,7 @@ flashcache_status(struct dm_target *ti, status_type_t type,
static struct target_type flashcache_target = {
.name = "flashcache",
- .version= {1, 0, 1},
+ .version= {1, 0, 3},
.module = THIS_MODULE,
.ctr = flashcache_ctr,
.dtr = flashcache_dtr,
@@ -41,7 +41,7 @@
void
usage(char *pname)
{
- fprintf(stderr, "Usage: %s [-p back|thru|around] [-b block size] [-m md block size] [-s cache size] [-a associativity] cachedev ssd_devname disk_devname\n", pname);
+ fprintf(stderr, "Usage: %s [-v] [-p back|thru|around] [-b block size] [-m md block size] [-s cache size] [-a associativity] cachedev ssd_devname disk_devname\n", pname);
fprintf(stderr, "Usage : %s Cache Mode back|thru|around is required argument\n",
pname);
fprintf(stderr, "Usage : %s Default units for -b, -m, -s are sectors, use k/m/g allowed. Default associativity is 512\n",
@@ -306,10 +306,10 @@ main(int argc, char **argv)
exit(1);
}
}
- sprintf(dmsetup_cmd, "echo 0 %lu flashcache %s %s %d 2 %lu %lu %lu %lu"
+ sprintf(dmsetup_cmd, "echo 0 %lu flashcache %s %s %s %d 2 %lu %lu %lu %lu"
" | dmsetup create %s",
- disk_devsize, disk_devname, ssd_devname, cache_mode, block_size,
- cache_size, associativity, md_block_size,
+ disk_devsize, disk_devname, ssd_devname, cachedev, cache_mode, block_size,
+ cache_size, associativity, md_block_size,
cachedev);
/* Go ahead and create the cache.
Oops, something went wrong. Retry.

0 comments on commit e6c43fc

Please sign in to comment.