Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Lazy initialization #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions README-DKMS
Expand Up @@ -27,16 +27,14 @@ Boot from Flashcache
-------------------- --------------------
If you have initramfs-tools, then flashcache utils and modules can be installed into the initramfs. If you have initramfs-tools, then flashcache utils and modules can be installed into the initramfs.
- Follow Installation section above. - Follow Installation section above.
- Install flashcache into the boot environment:
make install
- Install flashcache boot support: - Install flashcache boot support:
make -f Makefile.dkms boot_conf 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. - 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) (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: - 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 flashcache_create -l -p back fc-root /dev/ssd_device /dev/disk/by-uuid/root_device_uuid
- Reboot! - Reboot!


Known Issues: Known Issues:
Expand Down
57 changes: 53 additions & 4 deletions src/utils/flashcache_create.c
Expand Up @@ -41,7 +41,7 @@
void void
usage(char *pname) usage(char *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 [-v] [-l] [-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", fprintf(stderr, "Usage : %s Cache Mode back|thru|around is required argument\n",
pname); pname);
fprintf(stderr, "Usage : %s Default units for -b, -m, -s are sectors, use k/m/g allowed. Default associativity is 512\n", fprintf(stderr, "Usage : %s Default units for -b, -m, -s are sectors, use k/m/g allowed. Default associativity is 512\n",
Expand Down Expand Up @@ -176,9 +176,10 @@ main(int argc, char **argv)
int ret; int ret;
int cache_mode = -1; int cache_mode = -1;
char *cache_mode_str; char *cache_mode_str;

int lazy = 0;

pname = argv[0]; pname = argv[0];
while ((c = getopt(argc, argv, "fs:b:m:va:p:")) != -1) { while ((c = getopt(argc, argv, "lfs:b:m:va:p:")) != -1) {
switch (c) { switch (c) {
case 's': case 's':
cache_size = get_cache_size(optarg); cache_size = get_cache_size(optarg);
Expand All @@ -200,6 +201,9 @@ main(int argc, char **argv)
case 'f': case 'f':
force = 1; force = 1;
break; break;
case 'l':
lazy = 1;
break;
case 'p': case 'p':
if (strcmp(optarg, "back") == 0) { if (strcmp(optarg, "back") == 0) {
cache_mode = FLASHCACHE_WRITE_BACK; cache_mode = FLASHCACHE_WRITE_BACK;
Expand Down Expand Up @@ -240,7 +244,7 @@ main(int argc, char **argv)
else else
printf("block_size %lu, cache_size %lu\n", printf("block_size %lu, cache_size %lu\n",
block_size, cache_size); block_size, cache_size);
cache_fd = open(ssd_devname, O_RDONLY); cache_fd = open(ssd_devname, O_RDWR);
if (cache_fd < 0) { if (cache_fd < 0) {
fprintf(stderr, "Failed to open %s\n", ssd_devname); fprintf(stderr, "Failed to open %s\n", ssd_devname);
exit(1); exit(1);
Expand Down Expand Up @@ -306,6 +310,51 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
} }

if (lazy) {
if (cache_mode != FLASHCACHE_WRITE_BACK) {
fprintf(stderr, "Lazy initialization can only be used with writeback mode!\n");
exit(1);
}

struct flash_superblock *header = (struct flash_superblock *)malloc(512);

if (!header) {
fprintf(stderr, "Failed to allocate superblock memory\n");
exit(1);
}

memset(header, 0, 512);

if (!cache_size)
cache_size = cache_devsize;

cache_size = (cache_size / block_size) - 512;
cache_size = (cache_size / associativity) * associativity;

header->size = cache_size;
header->block_size = block_size;
header->md_block_size = md_block_size;
header->assoc = associativity;
header->cache_sb_state = CACHE_MD_STATE_DIRTY;
strncpy(header->disk_devname, disk_devname, DEV_PATHLEN);
strncpy(header->cache_devname, cachedev, DEV_PATHLEN);
header->disk_devsize = disk_devsize;
header->cache_devsize = cache_devsize;
header->cache_version = FLASHCACHE_VERSION;

lseek(cache_fd, 0, SEEK_SET);
if (write(cache_fd, header, 512) < 0) {
fprintf(stderr, "Cannot write Flashcache superblock to %s\n", ssd_devname);
exit(1);
}

if (verbose)
fprintf(stderr, "Wrote FlashCache superblock to %s\n", ssd_devname);

exit(0);
}

sprintf(dmsetup_cmd, "echo 0 %lu flashcache %s %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", " | dmsetup create %s",
disk_devsize, disk_devname, ssd_devname, cachedev, cache_mode, block_size, disk_devsize, disk_devname, ssd_devname, cachedev, cache_mode, block_size,
Expand Down