diff --git a/.gitignore b/.gitignore index fa6a678..7cccfa0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.a *.o *.o.* *.mod @@ -7,6 +8,7 @@ *.mk *.symvers *.order +*.swp src/rapiddisk test/rxflush test/rxio diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..2ce1db1 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,16 @@ +AUTHOR / MAINTAINER +Petros Koutoupis + +CONTRIBUTORS + +James Plummer +Gustaf Ullberg +Dmitry Trikoz +Neo +Efstathiou Efstathios +Marcel Huber +Steven Rudolph +Oliver Rath +Scott McGillivray +Boian Berberov +Shub77 diff --git a/CHANGELOG.md b/CHANGELOG.md index d623dc1..defda67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +### Release 6.1 ### + +- kernel: added support for 5.7 kernel +- utility: fixed GCC compilation warnings +- utility: code style cleanup +- installer: additional dkms installation/removal cleanup (thank you Shub77) +- documentation: fixed / updated README to reflect newer dkms installation/removal instructions +- documentation: updated copyright dates +- documentation: added AUTHORS file +- misc: added experimental scripts to enable rapiddisk/cache on root device during boot (thank you Shub77) + ### Release 6.0-1 ### - kernel: Fix dkms version in module/Makefile. diff --git a/README.md b/README.md index 6b57de2..29ef755 100644 --- a/README.md +++ b/README.md @@ -95,10 +95,3 @@ Uninstalling modules for DKMS support ```console # make dkms-uninstall ``` - -Contact -------- - -If you have any questions or concerns, do not contact -Petros Koutoupis (). Instead, contact your -congressman or congresswoman. I am trying to be politically correct here. diff --git a/conf/rapiddisk.sh.pacemaker b/conf/rapiddisk.sh.pacemaker index 3e87cf3..411efc6 100755 --- a/conf/rapiddisk.sh.pacemaker +++ b/conf/rapiddisk.sh.pacemaker @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2015-2018 Petros Koutoupis. All rights reserved. +# Copyright (C) 2015-2020 Petros Koutoupis. All rights reserved. # PATH=/bin:/sbin:/usr/bin:/usr/sbin diff --git a/conf/rapiddisk.sh.rgmanager b/conf/rapiddisk.sh.rgmanager index 3954e29..78a22f7 100755 --- a/conf/rapiddisk.sh.rgmanager +++ b/conf/rapiddisk.sh.rgmanager @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2015 - 2018 Petros Koutoupis. All rights reserved. +# Copyright (C) 2015 - 2020 Petros Koutoupis. All rights reserved. # PATH=/bin:/sbin:/usr/bin:/usr/sbin diff --git a/misc/README.md b/misc/rapiddisk-rootdev/README.md similarity index 100% rename from misc/README.md rename to misc/rapiddisk-rootdev/README.md diff --git a/misc/centos/96rapiddisk/module-setup.sh b/misc/rapiddisk-rootdev/centos/96rapiddisk/module-setup.sh similarity index 100% rename from misc/centos/96rapiddisk/module-setup.sh rename to misc/rapiddisk-rootdev/centos/96rapiddisk/module-setup.sh diff --git a/misc/centos/96rapiddisk/run_rapiddisk.sh b/misc/rapiddisk-rootdev/centos/96rapiddisk/run_rapiddisk.sh similarity index 100% rename from misc/centos/96rapiddisk/run_rapiddisk.sh rename to misc/rapiddisk-rootdev/centos/96rapiddisk/run_rapiddisk.sh diff --git a/misc/install_initrd.sh b/misc/rapiddisk-rootdev/install_initrd.sh similarity index 100% rename from misc/install_initrd.sh rename to misc/rapiddisk-rootdev/install_initrd.sh diff --git a/misc/ubuntu/rapiddisk b/misc/rapiddisk-rootdev/ubuntu/rapiddisk similarity index 100% rename from misc/ubuntu/rapiddisk rename to misc/rapiddisk-rootdev/ubuntu/rapiddisk diff --git a/misc/ubuntu/rapiddisk_hook b/misc/rapiddisk-rootdev/ubuntu/rapiddisk_hook similarity index 100% rename from misc/ubuntu/rapiddisk_hook rename to misc/rapiddisk-rootdev/ubuntu/rapiddisk_hook diff --git a/module/Makefile b/module/Makefile index 2452bc9..3dffc57 100644 --- a/module/Makefile +++ b/module/Makefile @@ -1,4 +1,4 @@ -# Copyright © 2011-2018 Petros Koutoupis +# Copyright © 2011-2020 Petros Koutoupis # All rights reserved. # # This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: GPL-2.0-only -VERSION = 6.0 +VERSION = 6.1 ifeq ($(KSRC),) KSRC := /lib/modules/$(shell uname -r)/build @@ -49,7 +49,7 @@ uninstall: clean: rm -rf *.o *.ko *.symvers *.mod.c .*.cmd Module.markers modules.order *.o.* built-in* - rm -rf .tmp_versions .rapiddisk.o.d *.unsigned *.sdtinfo.c .ctf/ .cache.mk + rm -rf .tmp_versions .rapiddisk.o.d *.unsigned *.sdtinfo.c .ctf/ .cache.mk *.mod dkms-install: ifeq ($(shell which dkms >/dev/null 2>/dev/null; echo $$?),1) diff --git a/module/dkms.conf b/module/dkms.conf index 8807acb..7f725e2 100644 --- a/module/dkms.conf +++ b/module/dkms.conf @@ -1,5 +1,5 @@ PACKAGE_NAME="rapiddisk" -PACKAGE_VERSION="6.0" +PACKAGE_VERSION="6.1" BUILT_MODULE_NAME[0]="rapiddisk" BUILT_MODULE_NAME[1]="rapiddisk-cache" DEST_MODULE_LOCATION[0]="/kernel/rapiddisk/" diff --git a/module/rapiddisk-cache.c b/module/rapiddisk-cache.c index 6cb1a9a..88ec8f9 100644 --- a/module/rapiddisk-cache.c +++ b/module/rapiddisk-cache.c @@ -1,5 +1,5 @@ /******************************************************************************* - ** Copyright © 2011-2019 Petros Koutoupis + ** Copyright © 2011 - 2020 Petros Koutoupis ** All rights reserved. ** ** This program is free software: you can redistribute it and/or modify @@ -59,7 +59,7 @@ } \ } while (0) -#define VERSION_STR "6.0" +#define VERSION_STR "6.1" #define DM_MSG_PREFIX "rapiddisk-cache" #define READCACHE 1 @@ -1239,7 +1239,7 @@ cache_status(struct dm_target *ti, status_type_t type, unsigned status_flags, static struct target_type cache_target = { .name = "rapiddisk-cache", - .version = {6, 0, 0}, + .version = {6, 1, 0}, .module = THIS_MODULE, .ctr = cache_ctr, .dtr = cache_dtr, @@ -1281,4 +1281,4 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Petros Koutoupis "); MODULE_DESCRIPTION("RapidDisk-Cache DM target is a write-through caching target with RapidDisk volumes."); MODULE_VERSION(VERSION_STR); -MODULE_INFO(Copyright, "Copyright 2010 - 2019 Petros Koutoupis"); +MODULE_INFO(Copyright, "Copyright 2010 - 2020 Petros Koutoupis"); diff --git a/module/rapiddisk.c b/module/rapiddisk.c index e2613f4..5e0cf1c 100644 --- a/module/rapiddisk.c +++ b/module/rapiddisk.c @@ -1,5 +1,5 @@ /******************************************************************************* - ** Copyright © 2011-2019 Petros Koutoupis + ** Copyright © 2011 - 2020 Petros Koutoupis ** All rights reserved. ** ** This program is free software: you can redistribute it and/or modify @@ -41,7 +41,7 @@ #include #include -#define VERSION_STR "6.0" +#define VERSION_STR "6.1" #define PREFIX "rapiddisk" #define BYTES_PER_SECTOR 512 #define MAX_RDSKS 128 @@ -703,10 +703,16 @@ static int attach_device(int size) spin_lock_init(&rdsk->rdsk_lock); INIT_RADIX_TREE(&rdsk->rdsk_pages, GFP_ATOMIC); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0) + rdsk->rdsk_queue = blk_alloc_queue(rdsk_make_request, NUMA_NO_NODE); + if (!rdsk->rdsk_queue) + goto out_free_dev; +#else rdsk->rdsk_queue = blk_alloc_queue(GFP_KERNEL); if (!rdsk->rdsk_queue) goto out_free_dev; blk_queue_make_request(rdsk->rdsk_queue, rdsk_make_request); +#endif blk_queue_logical_block_size(rdsk->rdsk_queue, BYTES_PER_SECTOR); blk_queue_physical_block_size(rdsk->rdsk_queue, PAGE_SIZE); #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) @@ -857,4 +863,4 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Petros Koutoupis "); MODULE_DESCRIPTION("RapidDisk is an enhanced RAM disk block device driver."); MODULE_VERSION(VERSION_STR); -MODULE_INFO(Copyright, "Copyright 2010 - 2019 Petros Koutoupis"); +MODULE_INFO(Copyright, "Copyright 2010 - 2020 Petros Koutoupis"); diff --git a/pkg-mgmt/debian/changelog b/pkg-mgmt/debian/changelog index 7636135..48a2ac4 100644 --- a/pkg-mgmt/debian/changelog +++ b/pkg-mgmt/debian/changelog @@ -1,3 +1,13 @@ +rapiddisk (6.1-1) released; urgency=medium +* kernel: added support for 5.7 kernel +* utility: fixed GCC compilation warnings +* utility: code style cleanup +* installer: additional dkms installation/removal cleanup (thank you Shub77) +* documentation: fixed / updated README to reflect newer dkms installation/removal instructions +* documentation: updated copyright dates +* documentation: added AUTHORS file +* misc: added experimental scripts to enable rapiddisk/cache on root device during boot (thank you Shub77) + rapiddisk (6.0-1) released; urgency=medium * kernel: Fixed module compilation error with modern version of GCC. diff --git a/pkg-mgmt/debian/control b/pkg-mgmt/debian/control index 671ca69..ee03e32 100755 --- a/pkg-mgmt/debian/control +++ b/pkg-mgmt/debian/control @@ -1,5 +1,5 @@ Package: rapiddisk -Version: 6.0-1 +Version: 6.1-1 Section: base Priority: optional Architecture: amd64 diff --git a/pkg-mgmt/debian/postinst b/pkg-mgmt/debian/postinst index c23bbd2..7ee1b97 100755 --- a/pkg-mgmt/debian/postinst +++ b/pkg-mgmt/debian/postinst @@ -16,9 +16,9 @@ fi case "$1" in configure) - dkms add -m rapiddisk -v 6.0 - dkms build -m rapiddisk -v 6.0 - dkms install -m rapiddisk -v 6.0 + dkms add -m rapiddisk -v 6.1 + dkms build -m rapiddisk -v 6.1 + dkms install -m rapiddisk -v 6.1 echo "rapiddisk max_sectors=2048 nr_requests=1024" >> /etc/modules echo "rapiddisk-cache" >> /etc/modules echo "dm_mod" >> /etc/modules diff --git a/pkg-mgmt/debian/prerm b/pkg-mgmt/debian/prerm index 22d95b0..0d394ae 100755 --- a/pkg-mgmt/debian/prerm +++ b/pkg-mgmt/debian/prerm @@ -14,7 +14,7 @@ fi case "$1" in remove|upgrade|deconfigure) - dkms remove -m rapiddisk -v 5.2 --all + dkms remove -m rapiddisk -v 6.0 --all ;; failed-upgrade) diff --git a/pkg-mgmt/spec/rapiddisk.spec.opensuse b/pkg-mgmt/spec/rapiddisk.spec.opensuse index 0a01c23..7c7c146 100644 --- a/pkg-mgmt/spec/rapiddisk.spec.opensuse +++ b/pkg-mgmt/spec/rapiddisk.spec.opensuse @@ -1,6 +1,6 @@ Summary: The RapidDisk software defined advanced RAM drive and storage caching solution. Name: rapiddisk -Version: 6.0 +Version: 6.1 Release: 1 License: General Public License Version 2 Group: Applications/System @@ -79,6 +79,15 @@ rm -rf %{buildroot} %doc %attr(0444,root,root) /usr/share/man/man1/* %changelog +* Thu May 26 2020 Petros Koutoupis +- kernel: added support for 5.7 kernel +- utility: fixed GCC compilation warnings +- utility: code style cleanup +- installer: additional dkms installation/removal cleanup (thank you Shub77) +- documentation: fixed / updated README to reflect newer dkms installation/removal instructions +- documentation: updated copyright dates +- documentation: added AUTHORS file +- misc: added experimental scripts to enable rapiddisk/cache on root device during boot (thank you Shub77) * Thu May 2 2019 Petros Koutoupis - kernel: Fixed module compilation error with modern version of GCC. - utility: Remove dm-crypt code; Not sure why i had it in the first place. Doesn't really belong. Just use cryptsetup. diff --git a/pkg-mgmt/spec/rapiddisk.spec.rhel6 b/pkg-mgmt/spec/rapiddisk.spec.rhel6 index e247c01..3474da7 100644 --- a/pkg-mgmt/spec/rapiddisk.spec.rhel6 +++ b/pkg-mgmt/spec/rapiddisk.spec.rhel6 @@ -1,6 +1,6 @@ Summary: The RapidDisk software defined advanced RAM drive and storage caching solution. Name: rapiddisk -Version: 6.0 +Version: 6.1 Release: 1 License: General Public License Version 2 Group: Applications/System @@ -78,6 +78,15 @@ rm -rf %{buildroot} %doc %attr(0444,root,root) /usr/share/man/man1/* %changelog +* Thu May 26 2020 Petros Koutoupis +- kernel: added support for 5.7 kernel +- utility: fixed GCC compilation warnings +- utility: code style cleanup +- installer: additional dkms installation/removal cleanup (thank you Shub77) +- documentation: fixed / updated README to reflect newer dkms installation/removal instructions +- documentation: updated copyright dates +- documentation: added AUTHORS file +- misc: added experimental scripts to enable rapiddisk/cache on root device during boot (thank you Shub77) * Thu May 2 2019 Petros Koutoupis - kernel: Fixed module compilation error with modern version of GCC. - utility: Remove dm-crypt code; Not sure why i had it in the first place. Doesn't really belong. Just use cryptsetup. diff --git a/pkg-mgmt/spec/rapiddisk.spec.rhel7+ b/pkg-mgmt/spec/rapiddisk.spec.rhel7+ index 9baf53c..9c55384 100644 --- a/pkg-mgmt/spec/rapiddisk.spec.rhel7+ +++ b/pkg-mgmt/spec/rapiddisk.spec.rhel7+ @@ -1,6 +1,6 @@ Summary: The RapidDisk software defined advanced RAM drive and storage caching solution. Name: rapiddisk -Version: 6.0 +Version: 6.1 Release: 1 License: General Public License Version 2 Group: Applications/System @@ -78,6 +78,15 @@ rm -rf %{buildroot} %doc %attr(0444,root,root) /usr/share/man/man1/* %changelog +* Thu May 26 2020 Petros Koutoupis +- kernel: added support for 5.7 kernel +- utility: fixed GCC compilation warnings +- utility: code style cleanup +- installer: additional dkms installation/removal cleanup (thank you Shub77) +- documentation: fixed / updated README to reflect newer dkms installation/removal instructions +- documentation: updated copyright dates +- documentation: added AUTHORS file +- misc: added experimental scripts to enable rapiddisk/cache on root device during boot (thank you Shub77) * Thu May 2 2019 Petros Koutoupis - kernel: Fixed module compilation error with modern version of GCC. - utility: Remove dm-crypt code; Not sure why i had it in the first place. Doesn't really belong. Just use cryptsetup. diff --git a/src/Makefile b/src/Makefile index eab27d3..8ab1493 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -# Copyright © 2011 - 2018 Petros Koutoupis +# Copyright © 2011 - 2020 Petros Koutoupis # All rights reserved. # # This file is part of RapidDisk. diff --git a/src/common.h b/src/common.h index 255a48c..7ee49a7 100644 --- a/src/common.h +++ b/src/common.h @@ -1,5 +1,5 @@ /********************************************************************************* - ** Copyright © 2011 - 2019 Petros Koutoupis + ** Copyright © 2011 - 2020 Petros Koutoupis ** All rights reserved. ** ** This file is part of RapidDisk. @@ -39,17 +39,15 @@ #include #include #include -#include #define UTIL "rapiddisk" -#define COPYRIGHT "Copyright 2011 - 2019 Petros Koutoupis" -#define VERSION_NUM "6.0" -#define SUCCESS 0x0 +#define COPYRIGHT "Copyright 2011 - 2020 Petros Koutoupis" +#define VERSION_NUM "6.1" +#define SUCCESS 0 +#define INVALID_VALUE -1 #define NAMELEN 0x200 -#define BYTES_PER_SECTOR 0x200 #define BUFSZ 0x10000 #define SYS_RDSK "/sys/kernel/rapiddisk/mgmt" -#define KEY_FILE "/etc/rapiddisk/key" #define WRITETHROUGH 0 #define WRITEAROUND 1 diff --git a/src/core.c b/src/core.c index c0a8362..f48e753 100644 --- a/src/core.c +++ b/src/core.c @@ -1,5 +1,5 @@ /********************************************************************************* - ** Copyright © 2011 - 2019 Petros Koutoupis + ** Copyright © 2011 - 2020 Petros Koutoupis ** All rights reserved. ** ** This file is part of RapidDisk. @@ -36,9 +36,8 @@ #include #endif -#define FILEDATA 0x40 -#define DEFAULT_SIZE 0x20 /* In MBytes */ - +#define FILEDATA 0x40 +#define BYTES_PER_SECTOR 0x200 struct RD_PROFILE *head = (struct RD_PROFILE *) NULL; struct RD_PROFILE *end = (struct RD_PROFILE *) NULL; @@ -55,7 +54,7 @@ struct RC_PROFILE *search_cache(void); unsigned char *read_info(unsigned char *name, unsigned char *string) { - int err, len; + int len; unsigned char file[NAMELEN] = {0}; unsigned char buf[0xFF] = {0}; static unsigned char obuf[0xFF] = {0}; @@ -70,7 +69,7 @@ unsigned char *read_info(unsigned char *name, unsigned char *string) printf("%s: fopen: %s\n", __func__, strerror(errno)); return NULL; } - err = fread(buf, FILEDATA, 1, fp); + fread(buf, FILEDATA, 1, fp); len = strlen(buf); strncpy(obuf, buf, (len - 1)); sprintf(obuf, "%s", obuf); @@ -81,16 +80,16 @@ unsigned char *read_info(unsigned char *name, unsigned char *string) struct RD_PROFILE *search_targets(void) { - int err, n = 0; + int rc, n = 0; unsigned char file[NAMELEN] = {0}; struct dirent **list; struct RD_PROFILE *prof; - if ((err = scandir(sys_block, &list, NULL, NULL)) < 0) { + if ((rc = scandir(sys_block, &list, NULL, NULL)) < 0) { printf("%s: scandir: %s\n", __func__, strerror(errno)); return NULL; } - for (;n < err; n++) { + for (;n < rc; n++) { if (strncmp(list[n]->d_name, "rd", 2) == SUCCESS) { prof = (struct RD_PROFILE *)calloc(1, sizeof(struct RD_PROFILE)); if (prof == NULL) { @@ -296,13 +295,14 @@ int list_devices_json(struct RD_PROFILE *rd_prof, struct RC_PROFILE *rc_prof) int attach_device(struct RD_PROFILE *prof, unsigned long size) { - int dsk, err = -1; + int dsk; FILE *fp; unsigned char string[BUFSZ], name[16]; /* echo "rapiddisk attach 64" > /sys/kernel/rapiddisk/mgmt <- in sectors*/ for (dsk = 0; prof != NULL; dsk++) { - sprintf(string, "%s,%s", string, prof->device); + strcat(string, ","); + strcat(string, prof->device); prof = prof->next; } @@ -317,8 +317,8 @@ int attach_device(struct RD_PROFILE *prof, unsigned long size) printf("%s: fopen: %s: %s\n", __func__, SYS_RDSK, strerror(errno)); return -ENOENT; } - if ((err = fprintf(fp, "rapiddisk attach %llu\n", - ((unsigned long long)size * 1024))) < 0) { + if (fprintf(fp, "rapiddisk attach %llu\n", + ((unsigned long long)size * 1024)) < 0) { printf("%s: fprintf: %s\n", __func__, strerror(errno)); return -EIO; } @@ -329,33 +329,33 @@ int attach_device(struct RD_PROFILE *prof, unsigned long size) int detach_device(struct RD_PROFILE *rd_prof, RC_PROFILE * rc_prof, unsigned char *string) { - int err = -1; + int rc = INVALID_VALUE; FILE *fp; unsigned char *buf; /* echo "rapiddisk detach 1" > /sys/kernel/rapiddisk/mgmt */ while (rd_prof != NULL) { if (strcmp(string, rd_prof->device) == SUCCESS) - err = 0; + rc = SUCCESS; rd_prof = rd_prof->next; } - if (err != 0) { + if (rc != SUCCESS) { printf("Error. Device %s does not exist.\n", string); - return -1; + return INVALID_VALUE; } /* Check to make sure RapidDisk device isn't in a mapping */ while (rc_prof != NULL) { if (strcmp(string, rc_prof->cache) == SUCCESS) { printf("Error. Unable to remove %s.\nThis RapidDisk device is currently" " mapped as a cache drive to %s.\n\n", string, rc_prof->device); - return -1; + return INVALID_VALUE; } rc_prof = rc_prof->next; } if ((buf = (char *)malloc(BUFSZ)) == NULL) { printf("%s: malloc: Unable to allocate memory.\n", __func__); - return -1; + return INVALID_VALUE; } /* Here we are starting to check to see if the device is mounted */ @@ -367,7 +367,7 @@ int detach_device(struct RD_PROFILE *rd_prof, RC_PROFILE * rc_prof, unsigned cha fclose(fp); if ((strstr(buf, string) != NULL)) { printf("%s is currently mounted. Please \"umount\" and retry.\n", string); - return -1; + return INVALID_VALUE; } /* This is where we begin to detach the block device */ @@ -376,19 +376,19 @@ int detach_device(struct RD_PROFILE *rd_prof, RC_PROFILE * rc_prof, unsigned cha return -ENOENT; } - if ((err = fprintf(fp, "rapiddisk detach %s\n", string + 2)) < 0) { + if (fprintf(fp, "rapiddisk detach %s\n", string + 2) < 0) { printf("%s: fprintf: %s\n", __func__, strerror(errno)); return -EIO; } printf("Detached device %s\n", string); fclose(fp); - return 0; + return SUCCESS; } int resize_device(struct RD_PROFILE *prof, unsigned char *string, unsigned long size) { - int err = -1; + int rc = INVALID_VALUE; FILE *fp; /* echo "rapiddisk resize 1 128" > /sys/kernel/rapiddisk/mgmt */ @@ -398,11 +398,11 @@ int resize_device(struct RD_PROFILE *prof, unsigned char *string, unsigned long printf("Error. Please specify a size larger than %lu Mbytes\n", size); return -EINVAL; } - err = 0; + rc = SUCCESS; } prof = prof->next; } - if (err != 0) { + if (rc != SUCCESS) { printf("Error. Device %s does not exist.\n", string); return -ENOENT; } @@ -413,8 +413,8 @@ int resize_device(struct RD_PROFILE *prof, unsigned char *string, unsigned long return -ENOENT; } - if ((err = fprintf(fp, "rapiddisk resize %s %llu\n", string + 2, - ((unsigned long long)size * 1024))) < 0) { + if (fprintf(fp, "rapiddisk resize %s %llu\n", string + 2, + ((unsigned long long)size * 1024)) < 0) { printf("%s: fprintf: %s\n", __func__, strerror(errno)); return -EIO; } @@ -427,18 +427,18 @@ int resize_device(struct RD_PROFILE *prof, unsigned char *string, unsigned long int cache_map(struct RD_PROFILE *rd_prof, struct RC_PROFILE * rc_prof, unsigned char *cache, unsigned char *source, int mode) { - int err = -1, node, fd; + int rc = INVALID_VALUE, node, fd; unsigned long long source_sz = 0, cache_sz = 0; FILE *fp; - unsigned char *buf, string[BUFSZ], name[NAMELEN] = {0}, str[NAMELEN] = {0}, *dup, *token; + unsigned char *buf, string[BUFSZ], name[NAMELEN] = {0}, str[NAMELEN - 6] = {0}, *dup, *token; while (rd_prof != NULL) { if (strcmp(cache, rd_prof->device) == SUCCESS) { - err = 0; + rc = SUCCESS; } rd_prof = rd_prof->next; } - if (err != 0) { + if (rc != SUCCESS) { printf("Error. Device %s does not exist.\n", cache); return -ENOENT; } @@ -447,7 +447,7 @@ int cache_map(struct RD_PROFILE *rd_prof, struct RC_PROFILE * rc_prof, if (strncmp(source, "/dev/", 5) != SUCCESS) { printf("Error. Source device does not seem to be a normal block device listed\n" "in the /dev directory path.\n\n"); - return -1; + return INVALID_VALUE; } /* Check to make sure that cache/source devices are not in a mapping already */ while (rc_prof != NULL) { @@ -455,48 +455,48 @@ int cache_map(struct RD_PROFILE *rd_prof, struct RC_PROFILE * rc_prof, (strcmp(source+5, rc_prof->source) == SUCCESS)) { printf("Error. At least one of your cache/source devices is currently mapped to %s.\n\n", rc_prof->device); - return -1; + return INVALID_VALUE; } rc_prof = rc_prof->next; } if ((buf = (char *)malloc(BUFSZ)) == NULL) { printf("%s: malloc: Unable to allocate memory.\n", __func__); - return -1; + return INVALID_VALUE; } if ((fp = fopen(etc_mtab, "r")) == NULL) { printf("%s: fopen: %s: %s\n", __func__, etc_mtab, strerror(errno)); - return -1; + return INVALID_VALUE; } fread(buf, BUFSZ, 1, fp); fclose(fp); if ((strstr(buf, cache) != NULL)) { printf("%s is currently mounted. Please \"umount\" and retry.\n", cache); - return -1; + return INVALID_VALUE; } if ((strstr(buf, source) != NULL)) { printf("%s is currently mounted. Please \"umount\" and retry.\n", source); - return -1; + return INVALID_VALUE; } - if ((fd = open(source, O_RDONLY)) < 0) { + if ((fd = open(source, O_RDONLY)) < SUCCESS) { printf("%s: open: %s\n", __func__, strerror(errno)); return -ENOENT; } - if (ioctl(fd, BLKGETSIZE, &source_sz) == -1) { + if (ioctl(fd, BLKGETSIZE, &source_sz) == INVALID_VALUE) { printf("%s: ioctl: %s\n", __func__, strerror(errno)); return -EIO; } close(fd); sprintf(name, "/dev/%s", cache); - if ((fd = open(name, O_RDONLY)) < 0) { + if ((fd = open(name, O_RDONLY)) < SUCCESS) { printf("%s: open: %s\n", __func__, strerror(errno)); return -ENOENT; } - if (ioctl(fd, BLKGETSIZE, &cache_sz) == -1) { + if (ioctl(fd, BLKGETSIZE, &cache_sz) == INVALID_VALUE) { printf("%s: ioctl: %s\n", __func__, strerror(errno)); return -EIO; } @@ -522,28 +522,29 @@ int cache_map(struct RD_PROFILE *rd_prof, struct RC_PROFILE * rc_prof, 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 ((err = system(string)) == 0) { + if ((rc = system(string)) == SUCCESS) { printf("Command to map %s with %s and %s has been sent.\nVerify with \"--list\"\n\n", name, cache, source); } else printf("Error. Unable to create map. Please verify all input values are correct.\n\n"); - return err; + return rc; } int cache_unmap(struct RC_PROFILE *prof, unsigned char *string) { - int err = -1; + int rc = INVALID_VALUE; FILE *fp; unsigned char *buf; unsigned char cmd[NAMELEN] = {0}; /* dmsetup remove rc-wt_sdb */ while (prof != NULL) { - if (strcmp(string, prof->device) == SUCCESS) err = 0; + if (strcmp(string, prof->device) == SUCCESS) + rc = SUCCESS; prof = prof->next; } - if (err != 0) { + if (rc != SUCCESS) { printf("Error. Cache target %s does not exist.\n", string); return -ENOENT; } @@ -566,26 +567,27 @@ int cache_unmap(struct RC_PROFILE *prof, unsigned char *string) } sprintf(cmd, "dmsetup remove %s\n", string); - if ((err = system(cmd)) == SUCCESS) + if ((rc = system(cmd)) == SUCCESS) printf("Command to unmap %s has been sent\nVerify with \"--list\"\n\n", string); else { printf("Error. Unable to unmap %s. Please check to make sure " "nothing is wrong.n\n", string); } - return err; + return rc; } int rdsk_flush(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigned char *string) { - int fd, err = -1; + int fd, rc = INVALID_VALUE; unsigned char file[NAMELEN] = {0}, *buf; FILE *fp; while (rd_prof != NULL) { - if (strcmp(string, rd_prof->device) == SUCCESS) err = 0; + if (strcmp(string, rd_prof->device) == SUCCESS) + rc = SUCCESS; rd_prof = rd_prof->next; } - if (err != 0) { + if (rc != SUCCESS) { printf("Error. Device %s does not exist.\n", string); return -ENOENT; } @@ -619,12 +621,12 @@ int rdsk_flush(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigned char *s sprintf(file, "/dev/%s", string); - if ((fd = open(file, O_WRONLY)) < 0) { + if ((fd = open(file, O_WRONLY)) < SUCCESS) { printf("%s: open: %s\n", __func__, strerror(errno)); return -ENOENT; } - if (ioctl(fd, BLKFLSBUF, 0) == -1) { + if (ioctl(fd, BLKFLSBUF, 0) == INVALID_VALUE) { printf("%s: ioctl: %s\n", __func__, strerror(errno)); return -EIO; } diff --git a/src/main.c b/src/main.c index bb584bd..222b4c8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /********************************************************************************* - ** Copyright © 2011 - 2019 Petros Koutoupis + ** Copyright © 2011 - 2020 Petros Koutoupis ** All rights reserved. ** ** This file is part of RapidDisk. @@ -87,86 +87,86 @@ void online_menu(char *string) "\trapiddisk --flush rd2\n\n"); } -int parse_input(int argcin, char *argvin[]) +int exec_cmdline_arg(int argcin, char *argvin[]) { - int err = 0, mode = WRITETHROUGH; - struct RD_PROFILE *rd; /* These are dummy pointers to */ - struct RC_PROFILE *rc; /* help create the linked list */ + int rc = INVALID_VALUE, mode = WRITETHROUGH; + struct RD_PROFILE *disk; /* These are dummy pointers to */ + struct RC_PROFILE *cache; /* help create the linked list */ printf("%s %s\n%s\n\n", UTIL, VERSION_NUM, COPYRIGHT); if ((argcin < 2) || (argcin > 5)) { online_menu(argvin[0]); - return err; + return rc; } if (((strcmp(argvin[1], "-h")) == 0) || ((strcmp(argvin[1],"-H")) == 0) || ((strcmp(argvin[1], "--help")) == 0)) { online_menu(argvin[0]); - return err; + return SUCCESS; } if (((strcmp(argvin[1], "-v")) == 0) || ((strcmp(argvin[1],"-V")) == 0) || ((strcmp(argvin[1], "--version")) == 0)) { - return err; + return SUCCESS; } - rd = (struct RD_PROFILE *)search_targets(); - rc = (struct RC_PROFILE *)search_cache(); + disk = (struct RD_PROFILE *)search_targets(); + cache = (struct RC_PROFILE *)search_cache(); if (strcmp(argvin[1], "--list") == 0) { - if (rd == NULL) + if (disk == NULL) printf("Unable to locate any RapidDisk devices.\n"); else - err = list_devices(rd, rc); + rc = list_devices(disk, cache); goto out; #if !defined NO_JANSSON } else if (strcmp(argvin[1], "--list-json") == 0) { - err = list_devices_json(rd, rc); + rc = list_devices_json(disk, cache); goto out; #endif } else if (strcmp(argvin[1], "--short-list") == 0) { - if (rd == NULL) + if (disk == NULL) printf("Unable to locate any RapidDisk devices.\n"); else - err = short_list_devices(rd, rc); + rc = short_list_devices(disk, cache); goto out; } if (strcmp(argvin[1], "--attach") == 0) { if (argcin != 3) goto invalid_out; - err = attach_device(rd, strtoul(argvin[2], (char **)NULL, 10)); + rc = attach_device(disk, strtoul(argvin[2], (char **)NULL, 10)); } else if (strcmp(argvin[1], "--detach") == 0) { if (argcin != 3) goto invalid_out; - if (rd == NULL) + if (disk == NULL) printf("Unable to locate any RapidDisk devices.\n"); else - err = detach_device(rd, rc, argvin[2]); + rc = detach_device(disk, cache, argvin[2]); } else if (strcmp(argvin[1], "--resize") == 0) { if (argcin != 4) goto invalid_out; - if (rd == NULL) + if (disk == NULL) printf("Unable to locate any RapidDisk devices.\n"); else - err = resize_device(rd, argvin[2], strtoul(argvin[3], (char **)NULL, 10)); + rc = resize_device(disk, argvin[2], strtoul(argvin[3], (char **)NULL, 10)); } else if (strcmp(argvin[1], "--cache-map") == 0) { if ((argcin < 4) || (argcin > 5)) goto invalid_out; if (argcin == 5) if (strcmp(argvin[4], "wa") == 0) mode = WRITEAROUND; - err = cache_map(rd, rc, argvin[2], argvin[3], mode); + rc = cache_map(disk, cache, argvin[2], argvin[3], mode); } else if (strcmp(argvin[1], "--cache-unmap") == 0) { if (argcin != 3) goto invalid_out; - err = cache_unmap(rc, argvin[2]); + rc = cache_unmap(cache, argvin[2]); } else if (strcmp(argvin[1], "--flush") == 0) { if (argcin != 3) goto invalid_out; - err = rdsk_flush(rd, rc, argvin[2]); + rc = rdsk_flush(disk, cache, argvin[2]); } else if (strcmp(argvin[1], "--stat-cache") == 0) { if (argcin != 3) goto invalid_out; - err = stat_cache_mapping(rc, argvin[2]); + rc = stat_cache_mapping(cache, argvin[2]); } else { goto invalid_out; } out: - return err; + return rc; invalid_out: printf("Error. Invalid argument(s) entered.\n"); return -EINVAL; @@ -174,16 +174,15 @@ int parse_input(int argcin, char *argvin[]) int main(int argc, char *argv[]) { - int err = 0; + int rc = INVALID_VALUE; FILE *fp; unsigned char string[BUFSZ]; if (getuid() != 0) { - printf("\nYou must be root or contain sudo permissions to " - "initiate this\napplication. technically you shouldn't " - "be running as root anyway.\n\n"); + printf("\nYou must be root or contain sudo permissions to initiate this\n\n"); return -EACCES; } + if (access(SYS_RDSK, F_OK) == -1) { printf("Please ensure that the RapidDisk module is loaded and retry.\n"); return -EPERM; @@ -201,6 +200,6 @@ int main(int argc, char *argv[]) return -EPERM; } - err = parse_input(argc, argv); - return err; + rc = exec_cmdline_arg(argc, argv); + return rc; } diff --git a/test/Makefile b/test/Makefile index 78fd1b0..e45f58b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -# Copyright © 2016 - 2018 Petros Koutoupis +# Copyright © 2016 - 2020 Petros Koutoupis # All rights reserved. # # This program is free software: you can redistribute it and/or modify diff --git a/test/rxflush.c b/test/rxflush.c index 1e33a3b..40009dd 100644 --- a/test/rxflush.c +++ b/test/rxflush.c @@ -1,6 +1,6 @@ /* rxio.c */ -/** Copyright © 2016 - 2018 Petros Koutoupis +/** Copyright © 2016 - 2020 Petros Koutoupis ** All rights reserved. ** ** This program is free software: you can redistribute it and/or modify @@ -31,17 +31,17 @@ #include int main (){ - int fd, err; + int fd, rc; - if((fd = open("/dev/rd0", O_WRONLY)) < 0){ - printf("%s\n", strerror(errno)); - return errno; - } + if((fd = open("/dev/rd0", O_WRONLY)) < 0){ + printf("%s\n", strerror(errno)); + return errno; + } - err = ioctl(fd, BLKFLSBUF, 0); - printf("Sent ioctl() BLKFLSBUF and got return: %d\n", err); + rc = ioctl(fd, BLKFLSBUF, 0); + printf("Sent ioctl() BLKFLSBUF and got return: %d\n", rc); - close (fd); + close (fd); - return 0; + return rc; } diff --git a/test/rxio.c b/test/rxio.c index 503432b..f79ce5e 100644 --- a/test/rxio.c +++ b/test/rxio.c @@ -1,6 +1,6 @@ /* rxio.c */ -/** Copyright © 2016 - 2018 Petros Koutoupis +/** Copyright © 2016 - 2020 Petros Koutoupis ** All rights reserved. ** ** This program is free software: you can redistribute it and/or modify @@ -35,47 +35,47 @@ #define BYTES_PER_BLOCK 512 int main (){ - int fd; - unsigned long long size; - unsigned char *buf; - off_t offset = 0; + int fd; + unsigned long long size; + unsigned char *buf; + off_t offset = 0; - buf = (char *)malloc(XFER_SIZE); - memset(buf, 0x2F, XFER_SIZE); + buf = (char *)malloc(XFER_SIZE); + memset(buf, 0x2F, XFER_SIZE); - if((fd = open("/dev/rd0", O_RDWR, O_NONBLOCK)) < 0){ - printf("%s\n", strerror(errno)); - return errno; - } + if((fd = open("/dev/rd0", O_RDWR, O_NONBLOCK)) < 0){ + printf("%s\n", strerror(errno)); + return errno; + } - if((ioctl(fd, BLKGETSIZE, &size)) == -1){ - printf("%s\n", strerror(errno)); - return errno; - }else{ - printf("total block count: %llu\n", size); - printf("total bytes count: %llu\n", (size * BYTES_PER_BLOCK)); - } + if((ioctl(fd, BLKGETSIZE, &size)) == -1){ + printf("%s\n", strerror(errno)); + return errno; + }else{ + printf("total block count: %llu\n", size); + printf("total bytes count: %llu\n", (size * BYTES_PER_BLOCK)); + } - if((write (fd, buf, XFER_SIZE)) <= 0){ - printf("%s\n", strerror(errno)); - return errno; - } - printf ("wrote %d bytes at offset %lu\n", XFER_SIZE, offset); + if((write (fd, buf, XFER_SIZE)) <= 0){ + printf("%s\n", strerror(errno)); + return errno; + } + printf ("wrote %d bytes at offset %lu\n", XFER_SIZE, offset); - offset = (offset + 65536); - if((lseek (fd, offset, SEEK_SET)) != offset){ - printf("%s\n", strerror(errno)); - return errno; - } - printf ("seeked to offset %lu\n", offset); + offset = (offset + 65536); + if((lseek (fd, offset, SEEK_SET)) != offset){ + printf("%s\n", strerror(errno)); + return errno; + } + printf ("seeked to offset %lu\n", offset); - if((read(fd, buf, XFER_SIZE)) <= 0){ - printf("%s\n", strerror(errno)); - return errno; - } - printf ("read %d bytes at offset %lu\n", XFER_SIZE, offset); + if((read(fd, buf, XFER_SIZE)) <= 0){ + printf("%s\n", strerror(errno)); + return errno; + } + printf ("read %d bytes at offset %lu\n", XFER_SIZE, offset); - close (fd); + close (fd); - return 0; + return 0; } diff --git a/test/rxioctl.c b/test/rxioctl.c index cd3adec..d7db9da 100644 --- a/test/rxioctl.c +++ b/test/rxioctl.c @@ -1,6 +1,6 @@ /* rxio.c */ -/** Copyright © 2016 - 2018 Petros Koutoupis +/** Copyright © 2016 - 2020 Petros Koutoupis ** All rights reserved. ** ** This program is free software: you can redistribute it and/or modify @@ -34,21 +34,21 @@ #define RD_GET_STATS 0x0529 int main (){ - int fd, max_sectors; + int fd, max_sectors; - if((fd = open("/dev/rd0", O_WRONLY)) < 0){ - printf("%s\n", strerror(errno)); - return errno; - } + if((fd = open("/dev/rd0", O_WRONLY)) < 0){ + printf("%s\n", strerror(errno)); + return errno; + } - if(ioctl(fd, RD_GET_STATS, &max_sectors) == -1){ - printf("%s\n", strerror(errno)); - return errno; - }else{ - printf("max sectors allocated: %d\n", max_sectors); - } + if(ioctl(fd, RD_GET_STATS, &max_sectors) == -1){ + printf("%s\n", strerror(errno)); + return errno; + }else{ + printf("max sectors allocated: %d\n", max_sectors); + } - close (fd); + close (fd); - return 0; + return 0; }