Skip to content

Commit

Permalink
Merge pull request #61 from pkoutoupis/feature/writecache_cli_wrapper
Browse files Browse the repository at this point in the history
Feature/writecache cli wrapper
  • Loading branch information
pkoutoupis authored Jun 12, 2021
2 parents 513af74 + 775cce1 commit 619d12c
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Release 7.2.0 ###

- module: Updated for 5.12 kernels and later (thank you Michael)
- utility: remove unused headers (thank you Marcel Huber)
- utility: add CLI support for dm-writecache wrapper
- utility: Fixed property check bug when parsing sysfs block subtree params (github issue #55)

### Release 7.1.0 ###

- module: Updated for 5.9 kernels and later
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
rapiddisk (7.2.0-1) released; urgency=medium

* module: Updated for 5.12 kernels and later (thank you Michael)
* utility: remove unused headers (thank you Marcel Huber)
* utility: add CLI support for dm-writecache wrapper
* utility: Fixed property check bug when parsing sysfs block subtree params (github issue #55)

rapiddisk (7.1.0-1) released; urgency=medium

* module: Updated for 5.9 kernels and later
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: rapiddisk
Version: 7.1.0-1
Version: 7.2.0-1
Section: base
Priority: optional
Architecture: amd64
Expand Down
6 changes: 3 additions & 3 deletions debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fi
case "$1" in

configure)
dkms add -m rapiddisk -v 7.1.0
dkms build -m rapiddisk -v 7.1.0
dkms install -m rapiddisk -v 7.1.0
dkms add -m rapiddisk -v 7.2.0
dkms build -m rapiddisk -v 7.2.0
dkms install -m rapiddisk -v 7.2.0
echo "rapiddisk max_sectors=2048 nr_requests=1024" >> /etc/modules
echo "rapiddisk-cache" >> /etc/modules
echo "dm_mod" >> /etc/modules
Expand Down
2 changes: 1 addition & 1 deletion debian/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi

case "$1" in
remove|upgrade|deconfigure)
dkms remove -m rapiddisk -v 7.1.0 --all
dkms remove -m rapiddisk -v 7.2.0 --all
;;

failed-upgrade)
Expand Down
5 changes: 4 additions & 1 deletion doc/rapiddisk.1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ List all attached RAM disk devices.
Map an RapidDisk device as a caching node to another block device.
.TP
-p
Define cache policy (default: write-through).
Define cache policy: write-through (wt), write-around (wa) or writeback (wb) (dangerous) (default: write-through).
Writeback caching is supplied by the dm-writecache kernel module and is not intended for production use as it may result in data loss on hardware/power failure.
.TP
-r
Dynamically grow the size of an existing RapidDisk device.
Expand Down Expand Up @@ -72,6 +73,8 @@ rapiddisk -m rd1 -b /dev/sdb
.TP
rapiddisk -m rd1 -b /dev/sdb -p wt
.TP
rapiddisk -m rd3 -b /dev/mapper/rc-wa_sdb -p wb
.TP
rapiddisk -u rc-wt_sdb
.TP
rapiddisk -s rc-wt_sdb
Expand Down
2 changes: 1 addition & 1 deletion misc/rapiddisk-legacy/rapiddisk-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi
## usage ##
function help_menu()
{
echo -e "$1 7.1.0"
echo -e "$1 7.2.0"
echo -e "Copyright 2011 - 2021 Petros Koutoupis"
echo -e ""
echo -e "$1 is an administration tool to manage the RapidDisk RAM disk devices and"
Expand Down
2 changes: 1 addition & 1 deletion module/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# SPDX-License-Identifier: GPL-2.0-only

VERSION = 7.1.0
VERSION = 7.2.0

ifeq ($(KSRC),)
KSRC := /lib/modules/$(shell uname -r)/build
Expand Down
2 changes: 1 addition & 1 deletion module/dkms.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME="rapiddisk"
PACKAGE_VERSION="7.1.0"
PACKAGE_VERSION="7.2.0"
BUILT_MODULE_NAME[0]="rapiddisk"
BUILT_MODULE_NAME[1]="rapiddisk-cache"
DEST_MODULE_LOCATION[0]="/kernel/rapiddisk/"
Expand Down
4 changes: 2 additions & 2 deletions module/rapiddisk-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
} \
} while (0)

#define VERSION_STR "7.1.0"
#define VERSION_STR "7.2.0"
#define DM_MSG_PREFIX "rapiddisk-cache"

#define READCACHE 1
Expand Down Expand Up @@ -1234,7 +1234,7 @@ cache_status(struct dm_target *ti, status_type_t type, unsigned status_flags,

static struct target_type cache_target = {
.name = "rapiddisk-cache",
.version = {7, 1, 0},
.version = {7, 2, 0},
.module = THIS_MODULE,
.ctr = cache_ctr,
.dtr = cache_dtr,
Expand Down
2 changes: 1 addition & 1 deletion module/rapiddisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <linux/radix-tree.h>
#include <linux/io.h>

#define VERSION_STR "7.1.0"
#define VERSION_STR "7.2.0"
#define PREFIX "rapiddisk"
#define BYTES_PER_SECTOR 512
#define MAX_RDSKS 128
Expand Down
7 changes: 6 additions & 1 deletion rapiddisk.spec.rhel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary: The RapidDisk software defined advanced RAM drive and storage caching solution.
Name: rapiddisk
Version: 7.1.0
Version: 7.2.0
Release: 1
License: General Public License Version 2
Group: Applications/System
Expand Down Expand Up @@ -78,6 +78,11 @@ rm -rf %{buildroot}
%doc %attr(0444,root,root) /usr/share/man/man1/*

%changelog
* Fri May 28 2021 Petros Koutoupis <[email protected]>
- module: Updated for 5.12 kernels and later (thank you Michael)
- utility: remove unused headers (thank you Marcel Huber)
- utility: add CLI support for dm-writecache wrapper
- utility: Fixed property check bug when parsing sysfs block subtree params (github issue #55)
* Thu Jan 21 2021 Petros Koutoupis <[email protected]>
- module: Updated for 5.9 kernels and later
- documentation: Updated copyrights
Expand Down
7 changes: 6 additions & 1 deletion rapiddisk.spec.sles
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary: The RapidDisk software defined advanced RAM drive and storage caching solution.
Name: rapiddisk
Version: 7.1.0
Version: 7.2.0
Release: 1
License: General Public License Version 2
Group: Applications/System
Expand Down Expand Up @@ -79,6 +79,11 @@ rm -rf %{buildroot}
%doc %attr(0444,root,root) /usr/share/man/man1/*

%changelog
* Fri May 28 2021 Petros Koutoupis <[email protected]>
- module: Updated for 5.12 kernels and later (thank you Michael)
- utility: remove unused headers (thank you Marcel Huber)
- utility: add CLI support for dm-writecache wrapper
- utility: Fixed property check bug when parsing sysfs block subtree params (github issue #55)
* Thu Jan 21 2021 Petros Koutoupis <[email protected]>
- module: Updated for 5.9 kernels and later
- documentation: Updated copyrights
Expand Down
3 changes: 2 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@
#define PROCESS "rapiddisk"
#define DAEMON PROCESS "d"
#define COPYRIGHT "Copyright 2011 - 2021 Petros Koutoupis"
#define VERSION_NUM "7.1.0"
#define VERSION_NUM "7.2.0"
#define SUCCESS 0
#define INVALID_VALUE -1
#define NAMELEN 0x200
#define BUFSZ 0x10000
#define PAYLOADSZ 0x80000 /* 512K: this is our max read limit for libcurl */
#define WRITETHROUGH 0
#define WRITEAROUND 1
#define WRITEBACK 2

typedef char bool;

Expand Down
12 changes: 10 additions & 2 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ int json_device_list(struct RD_PROFILE *rd, struct RC_PROFILE *rc)
json_t *root, *array = json_array();
json_t *rd_array = json_array(), *rc_array = json_array();
json_t *rd_object = json_object(), *rc_object = json_object() ;
unsigned char mode[0x20] = {0x0};

while (rd != NULL) {
json_t *object = json_object();
Expand All @@ -105,8 +106,15 @@ int json_device_list(struct RD_PROFILE *rd, struct RC_PROFILE *rc)
json_object_set_new(object, "device", json_string(rc->device));
json_object_set_new(object, "cache", json_string(rc->cache));
json_object_set_new(object, "source", json_string(rc->source));
json_object_set_new(object, "mode", json_string((strncmp(rc->device,
"rc-wt_", 5) == 0) ? "write-through" : "write-around"));
memset(mode, 0x0, sizeof(mode));
if (strncmp(rc->device, "rc-wt_", 5) == 0) {
sprintf(mode, "write-through");
} else if (strncmp(rc->device, "rc-wb_", 5) == 0) {
sprintf(mode, "writeback");
} else {
sprintf(mode, "write-around");
}
json_object_set_new(object, "mode", json_string(mode));
json_array_append_new(rc_array, object);
rc = rc->next;
}
Expand Down
19 changes: 18 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "common.h"
#include "cli.h"

bool writeback_enabled;

void online_menu(unsigned char *string)
{
printf("%s is an administration tool to manage RapidDisk RAM disk devices and\n"
Expand All @@ -48,7 +50,8 @@ void online_menu(unsigned char *string)
"\t-j\t\tEnable JSON formatted output.\n"
"\t-l\t\tList all attached RAM disk devices.\n"
"\t-m\t\tMap an RapidDisk device as a caching node to another block device.\n"
"\t-p\t\tDefine cache policy (default: write-through).\n"
"\t-p\t\tDefine cache policy: write-through, write-around or writeback \033[31;1m(dangerous)\033[0m\n"
"\t\t\t(default: write-through).\n"
"\t-r\t\tDynamically grow the size of an existing RapidDisk device.\n"
"\t-s\t\tObtain RapidDisk-Cache Mappings statistics.\n"
"\t-u\t\tUnmap a RapidDisk device from another block device.\n"
Expand All @@ -58,6 +61,7 @@ void online_menu(unsigned char *string)
"\trapiddisk -r rd2 -c 128\n"
"\trapiddisk -m rd1 -b /dev/sdb\n"
"\trapiddisk -m rd1 -b /dev/sdb -p wt\n"
"\trapiddisk -m rd3 -b /dev/mapper/rc-wa_sdb -p wb\n"
"\trapiddisk -u rc-wt_sdb\n"
"\trapiddisk -f rd2\n\n");
}
Expand Down Expand Up @@ -112,6 +116,14 @@ int exec_cmdline_arg(int argcin, char *argvin[])
case 'p':
if (strcmp(optarg, "wa") == 0)
mode = WRITEAROUND;
else if (strcmp(optarg, "wb") == 0) {
if (writeback_enabled == FALSE) {
printf("Please ensure that the dm-writecache module is "
"loaded and retry.\n");
return -EPERM;
} else
mode = WRITEBACK;
}
break;
case 'q':
action = ACTION_QUERY_RESOURCES;
Expand Down Expand Up @@ -277,6 +289,11 @@ int main(int argc, char *argv[])
return -EPERM;
}

writeback_enabled = FALSE;
if (strstr(string, "dm_writecache") != NULL) {
writeback_enabled = TRUE;
}

rc = exec_cmdline_arg(argc, argv);
return rc;
}
38 changes: 28 additions & 10 deletions src/rdsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,15 @@ int mem_device_list(struct RD_PROFILE *rd_prof, struct RC_PROFILE *rc_prof)
}
num = 1;
while (rc_prof != NULL) {
printf(" RapidDisk-Cache Target %d: %s\tCache: %s Target: %s (%s)\n",
num, rc_prof->device, rc_prof->cache, rc_prof->source,
(strncmp(rc_prof->device, "rc-wt_", 5) == 0) ? \
"WRITE THROUGH" : "WRITE AROUND");
if (strstr(rc_prof->device, "rc-wb") != NULL) {
printf(" dm-writecache Target %d: %s\tCache: %s Target: %s (WRITEBACK)\n",
num, rc_prof->device, rc_prof->cache, rc_prof->source);
} else {
printf(" RapidDisk-Cache Target %d: %s\tCache: %s Target: %s (%s)\n",
num, rc_prof->device, rc_prof->cache, rc_prof->source,
(strncmp(rc_prof->device, "rc-wt_", 5) == 0) ? \
"WRITE THROUGH" : "WRITE AROUND");
}
num++;
rc_prof = rc_prof->next;
}
Expand Down Expand Up @@ -502,16 +507,23 @@ int cache_device_map(struct RD_PROFILE *rd_prof, struct RC_PROFILE * rc_prof,
}
if (mode == WRITETHROUGH)
sprintf(name, "rc-wt_%s", str);
else if (mode == WRITEBACK) /* very dangerous mode */
sprintf(name, "rc-wb_%s", str);
else
sprintf(name, "rc-wa_%s", str);

memset(string, 0x0, BUFSZ);
/* echo 0 4194303 rapiddisk-cache /dev/sdb /dev/rd0 0 196608|dmsetup create rc-wt_sdb */
/* Param after echo 0 & 1: starting and ending offsets of source device *
* Param 3: always rapiddisk-cache; Param 4 & 5: path to source device and RapidDisk dev *
* Param 6: is the size of the cache */
sprintf(string, "echo 0 %llu rapiddisk-cache %s /dev/%s %llu %d|dmsetup create %s\n",
source_sz, source, cache, cache_sz, mode, name);
if (mode == WRITEBACK) /* very dangerous mode */
sprintf(string, "echo 0 %llu writecache s %s /dev/%s 4096 0|dmsetup create %s\n",
source_sz, source, cache, name);
else {
/* echo 0 4194303 rapiddisk-cache /dev/sdb /dev/rd0 0 196608|dmsetup create rc-wt_sdb */
/* Param after echo 0 & 1: starting and ending offsets of source device *
* Param 3: always rapiddisk-cache; Param 4 & 5: path to source device and RapidDisk dev *
* Param 6: is the size of the cache */
sprintf(string, "echo 0 %llu rapiddisk-cache %s /dev/%s %llu %d|dmsetup create %s\n",
source_sz, source, cache, cache_sz, mode, name);
}

if ((rc = system(string)) == SUCCESS) {
printf("Command to map %s with %s and %s has been sent.\nVerify with \"-l\"\n\n",
Expand Down Expand Up @@ -557,6 +569,12 @@ int cache_device_unmap(struct RC_PROFILE *prof, unsigned char *string)
return -EBUSY;
}

if (strstr(string, "rc-wb") != NULL) {
sprintf(cmd, "dmsetup message %s 0 flush\n", string);
if ((rc = system(cmd)) != SUCCESS)
printf("Unable to flush dirty cache data to %s\n", string);
}

sprintf(cmd, "dmsetup remove %s\n", string);
if ((rc = system(cmd)) == SUCCESS)
printf("Command to unmap %s has been sent\nVerify with \"-l\"\n\n", string);
Expand Down
14 changes: 11 additions & 3 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int get_memory_usage(struct MEM_PROFILE *mem)
struct VOLUME_PROFILE *search_volumes_targets(void)
{
int rc, n = 0, i;
unsigned char file[NAMELEN] = {0};
unsigned char file[NAMELEN] = {0}, test[NAMELEN + 32] = {0};
struct dirent **list;
struct VOLUME_PROFILE *volume = NULL;

Expand All @@ -74,13 +74,21 @@ struct VOLUME_PROFILE *search_volumes_targets(void)
sprintf(file, "%s/%s", SYS_BLOCK, list[n]->d_name);
volume->size = (BYTES_PER_SECTOR * strtoull(read_info(file, "size"), NULL, 10));
sprintf(file, "%s/%s/device", SYS_BLOCK, list[n]->d_name);
sprintf(volume->model, "%s", read_info(file, "model"));
sprintf(test, "%s/model", file);
if (access(test, F_OK) != INVALID_VALUE)
sprintf(volume->model, "%s", read_info(file, "model"));
else
sprintf(volume->model, "UNAVAILABLE");
/* trim whitespace of model string */
for (i = 0; i < strlen(volume->model); i++) {
if ((strncmp(volume->model + i, " ", 1) == SUCCESS) || (strncmp(volume->model + i, "\n", 1) == SUCCESS))
volume->model[i] = '\0';
}
sprintf(volume->vendor, "%s", read_info(file, "vendor"));
sprintf(test, "%s/vendor", file);
if (access(test, F_OK) != INVALID_VALUE)
sprintf(volume->vendor, "%s", read_info(file, "vendor"));
else
sprintf(volume->vendor, "UNAVAILABLE");
/* trim whitespace of vendor string */
for (i = 0; i < strlen(volume->vendor); i++) {
if ((strncmp(volume->vendor+ i, " ", 1) == SUCCESS) || (strncmp(volume->vendor + i, "\n", 1) == SUCCESS))
Expand Down

0 comments on commit 619d12c

Please sign in to comment.