diff options
-rw-r--r-- | CMakeLists.txt | 11 | ||||
-rw-r--r-- | kernel/CMakeLists.txt | 6 | ||||
-rw-r--r-- | utils/CMakeLists.txt | 3 | ||||
-rw-r--r-- | utils/include/loopdev.h | 4 | ||||
-rw-r--r-- | utils/include/pathnames.h | 4 | ||||
-rw-r--r-- | utils/lib/loopdev.c | 12 | ||||
-rw-r--r-- | utils/sys-utils/xlosetup.c | 60 |
7 files changed, 54 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ba17bf4..76439db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,17 @@ cmake_minimum_required(VERSION 3.10) # set the project name project(xloop) +# define project specific settings +set(BLK_DEV_XLOOP_MIN_COUNT 8 + CACHE STRING "Number of xloop devices to pre-create at init time") +set(XLOOP_MAJOR 120 + CACHE STRING "Major number for xloop devices") + +# print configured settings +message(STATUS "Number of xloop devices to pre-create at init time is " ${BLK_DEV_XLOOP_MIN_COUNT}) +message(STATUS "Major number for xloop devices is " ${XLOOP_MAJOR}) + +# set compilation in debug mode as default configuration if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug") endif() diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 7cc79dd..ffa97e6 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -11,17 +11,11 @@ set(KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}" CACHE PATH "Path to kernel sources to compile against") # define xloop device specific options -set(BLK_DEV_XLOOP_MIN_COUNT 8 - CACHE STRING "Number of xloop devices to pre-create at init time") -set(XLOOP_MAJOR 120 - CACHE STRING "Major number for xloop devices") set(XLOOP_CTRL_MINOR 15 CACHE STRING "Minor number for xloop-control device") # print configured settings message(STATUS "Kernel module path is " ${KERNEL_DIR}) -message(STATUS "Number of xloop devices to pre-create at init time is " ${BLK_DEV_XLOOP_MIN_COUNT}) -message(STATUS "Major number for xloop devices is " ${XLOOP_MAJOR}) message(STATUS "Minor number for xloop-control device is " ${XLOOP_CTRL_MINOR}) # set C flags for a Linux kernel module diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 7669fd9..df83a7a 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -10,6 +10,9 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) # add include of config.h to each source file add_compile_options(-include ${CMAKE_CURRENT_SOURCE_DIR}/config.h) +# add xloop specific compile options +add_definitions(-DCONFIG_BLK_DEV_XLOOP_MIN_COUNT=${BLK_DEV_XLOOP_MIN_COUNT} -DXLOOP_MAJOR=${XLOOP_MAJOR}) + add_subdirectory(lib) add_subdirectory(libsmartcols) add_subdirectory(sys-utils) diff --git a/utils/include/loopdev.h b/utils/include/loopdev.h index bc68e52..0221e6b 100644 --- a/utils/include/loopdev.h +++ b/utils/include/loopdev.h @@ -75,8 +75,8 @@ struct loop_info64 { uint32_t lo_file_fmt_type; }; -#define LOOPDEV_MAJOR 7 /* loop major number */ -#define LOOPDEV_DEFAULT_NNODES 8 /* default number of loop devices */ +#define LOOPDEV_MAJOR XLOOP_MAJOR /* loop major number */ +#define LOOPDEV_DEFAULT_NNODES CONFIG_BLK_DEV_XLOOP_MIN_COUNT /* default number of loop devices */ struct loopdev_iter { FILE *proc; /* /proc/partitions */ diff --git a/utils/include/pathnames.h b/utils/include/pathnames.h index 8f62337..8f1bb56 100644 --- a/utils/include/pathnames.h +++ b/utils/include/pathnames.h @@ -144,8 +144,8 @@ #define _PATH_DEV_MEM "/dev/mem" -#define _PATH_DEV_LOOP "/dev/loop" -#define _PATH_DEV_LOOPCTL "/dev/loop-control" +#define _PATH_DEV_LOOP "/dev/xloop" +#define _PATH_DEV_LOOPCTL "/dev/xloop-control" /* udev paths */ #define _PATH_DEV_BYLABEL "/dev/disk/by-label" diff --git a/utils/lib/loopdev.c b/utils/lib/loopdev.c index 57129bd..d377371 100644 --- a/utils/lib/loopdev.c +++ b/utils/lib/loopdev.c @@ -109,9 +109,9 @@ int loopcxt_set_device(struct loopdev_cxt *lc, const char *device) /* compose device name for /dev/xloop<n> or /dev/xloop/<n> */ if (lc->flags & LOOPDEV_FL_DEVSUBDIR) { - if (strlen(device) < 6) + if (strlen(device) <= 5) return -1; - device += 4; + device += 5; dir = _PATH_DEV_LOOP "/"; /* _PATH_DEV uses tailing slash */ } snprintf(lc->device, sizeof(lc->device), "%s%s", @@ -188,7 +188,7 @@ int loopcxt_init(struct loopdev_cxt *lc, int flags) if (!(lc->flags & LOOPDEV_FL_CONTROL) && !stat(_PATH_DEV_LOOPCTL, &st)) { lc->flags |= LOOPDEV_FL_CONTROL; - DBG(CXT, ul_debugobj(lc, "init: loop-control detected ")); + DBG(CXT, ul_debugobj(lc, "init: xloop-control detected ")); } return 0; @@ -1605,7 +1605,7 @@ int loopcxt_add_device(struct loopdev_cxt *lc) } p = strrchr(dev, '/'); - if (!p || (sscanf(p, "/loop%d", &nr) != 1 && sscanf(p, "/%d", &nr) != 1) + if (!p || (sscanf(p, "/xloop%d", &nr) != 1 && sscanf(p, "/%d", &nr) != 1) || nr < 0) goto done; @@ -1636,7 +1636,7 @@ int loopcxt_find_unused(struct loopdev_cxt *lc) if (lc->flags & LOOPDEV_FL_CONTROL) { int ctl; - DBG(CXT, ul_debugobj(lc, "using loop-control")); + DBG(CXT, ul_debugobj(lc, "using xloop-control")); ctl = open(_PATH_DEV_LOOPCTL, O_RDWR|O_CLOEXEC); if (ctl >= 0) @@ -1650,7 +1650,7 @@ int loopcxt_find_unused(struct loopdev_cxt *lc) lc->control_ok = ctl >= 0 && rc == 0 ? 1 : 0; if (ctl >= 0) close(ctl); - DBG(CXT, ul_debugobj(lc, "find_unused by loop-control [rc=%d]", rc)); + DBG(CXT, ul_debugobj(lc, "find_unused by xloop-control [rc=%d]", rc)); } if (rc < 0) { diff --git a/utils/sys-utils/xlosetup.c b/utils/sys-utils/xlosetup.c index cab1037..8a215ec 100644 --- a/utils/sys-utils/xlosetup.c +++ b/utils/sys-utils/xlosetup.c @@ -2,7 +2,7 @@ * Copyright (C) 2011 Karel Zak <kzak@redhat.com> * Originally from Ted's losetup.c * - * xlosetup.c - setup and control loop devices + * xlosetup.c - setup and control xloop devices */ #include <assert.h> #include <stdio.h> @@ -36,7 +36,7 @@ enum { A_FIND_FREE, /* find first unused */ A_SET_CAPACITY, /* set device capacity */ A_SET_DIRECT_IO, /* set accessing backing file by direct io */ - A_SET_BLOCKSIZE, /* set logical block size of the loop device */ + A_SET_BLOCKSIZE, /* set logical block size of the xloop device */ }; enum { @@ -75,12 +75,12 @@ static struct colinfo infos[] = { [COL_FILE_FMT_TYPE] = { "FILE-FORMAT", 1, 0, N_("backing file format")}, [COL_BACK_INO] = { "BACK-INO", 4, SCOLS_FL_RIGHT, N_("backing file inode number"), SCOLS_JSON_NUMBER}, [COL_BACK_MAJMIN] = { "BACK-MAJ:MIN", 6, 0, N_("backing file major:minor device number")}, - [COL_NAME] = { "NAME", 0.25, 0, N_("loop device name")}, + [COL_NAME] = { "NAME", 0.25, 0, N_("xloop device name")}, [COL_OFFSET] = { "OFFSET", 5, SCOLS_FL_RIGHT, N_("offset from the beginning"), SCOLS_JSON_NUMBER}, [COL_PARTSCAN] = { "PARTSCAN", 1, SCOLS_FL_RIGHT, N_("partscan flag set"), SCOLS_JSON_BOOLEAN}, [COL_RO] = { "RO", 1, SCOLS_FL_RIGHT, N_("read-only device"), SCOLS_JSON_BOOLEAN}, [COL_SIZELIMIT] = { "SIZELIMIT", 5, SCOLS_FL_RIGHT, N_("size limit of the file in bytes"), SCOLS_JSON_NUMBER}, - [COL_MAJMIN] = { "MAJ:MIN", 3, 0, N_("loop device major:minor number")}, + [COL_MAJMIN] = { "MAJ:MIN", 3, 0, N_("xloop device major:minor number")}, [COL_DIO] = { "DIO", 1, SCOLS_FL_RIGHT, N_("access backing file with direct-io"), SCOLS_JSON_BOOLEAN}, [COL_LOGSEC] = { "LOG-SEC", 4, SCOLS_FL_RIGHT, N_("logical sector size in bytes"), SCOLS_JSON_NUMBER}, }; @@ -343,7 +343,7 @@ static int show_table(struct loopdev_cxt *lc, scols_table_enable_noheadings(tb, no_headings); if (json) - scols_table_set_name(tb, "loopdevices"); + scols_table_set_name(tb, "xloopdevices"); for (i = 0; i < ncolumns; i++) { struct colinfo *ci = get_column_info(i); @@ -356,14 +356,14 @@ static int show_table(struct loopdev_cxt *lc, scols_column_set_json_type(cl, ci->json_type); } - /* only one loopdev requested (already assigned to loopdev_cxt) */ + /* only one xloopdev requested (already assigned to loopdev_cxt) */ if (loopcxt_get_device(lc)) { ln = scols_table_new_line(tb, NULL); if (!ln) err(EXIT_FAILURE, _("failed to allocate output line")); rc = set_scols_data(lc, ln); - /* list all loopdevs */ + /* list all xloopdevs */ } else { char *cn_file = NULL; @@ -413,20 +413,20 @@ static void __attribute__((__noreturn__)) usage(void) fputs(USAGE_HEADER, out); fprintf(out, - _(" %1$s [options] [<loopdev>]\n" - " %1$s [options] -f | <loopdev> <file>\n"), + _(" %1$s [options] [<xloopdev>]\n" + " %1$s [options] -f | <xloopdev> <file>\n"), program_invocation_short_name); fputs(USAGE_SEPARATOR, out); - fputs(_("Set up and control loop devices.\n"), out); + fputs(_("Set up and control xloop devices.\n"), out); /* commands */ fputs(USAGE_OPTIONS, out); fputs(_(" -a, --all list all used devices\n"), out); - fputs(_(" -d, --detach <loopdev>... detach one or more devices\n"), out); + fputs(_(" -d, --detach <xloopdev>... detach one or more devices\n"), out); fputs(_(" -D, --detach-all detach all used devices\n"), out); fputs(_(" -f, --find find first unused device\n"), out); - fputs(_(" -c, --set-capacity <loopdev> resize the device\n"), out); + fputs(_(" -c, --set-capacity <xloopdev> resize the device\n"), out); fputs(_(" -j, --associated <file> list all devices associated with <file>\n"), out); fputs(_(" -L, --nooverlap avoid possible conflict between devices\n"), out); @@ -435,8 +435,8 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -o, --offset <num> start at offset <num> into file\n"), out); fputs(_(" --sizelimit <num> device is limited to <num> bytes of the file\n"), out); fputs(_(" -b, --sector-size <num> set the logical sector size to <num>\n"), out); - fputs(_(" -P, --partscan create a partitioned loop device\n"), out); - fputs(_(" -r, --read-only set up a read-only loop device\n"), out); + fputs(_(" -P, --partscan create a partitioned xloop device\n"), out); + fputs(_(" -r, --read-only set up a read-only xloop device\n"), out); fputs(_(" --direct-io[=<on|off>] open backing file with O_DIRECT\n"), out); fputs(_(" --show print device name after setup (with -f)\n"), out); fputs(_(" -t, --type set file format type of the loop device\n"), out); @@ -477,7 +477,7 @@ static void warn_size(const char *filename, uint64_t size, uint64_t offset, int } if (size < 512) - warnx(_("%s: Warning: file is smaller than 512 bytes; the loop device " + warnx(_("%s: Warning: file is smaller than 512 bytes; the xloop device " "may be useless or invisible for system tools."), filename); else if (size % 512) @@ -503,37 +503,37 @@ static int create_loop(struct loopdev_cxt *lc, case 1: /* overlap */ loopcxt_deinit(lc); - errx(EXIT_FAILURE, _("%s: overlapping loop device exists"), file); + errx(EXIT_FAILURE, _("%s: overlapping xloop device exists"), file); case 2: /* overlap -- full size and offset match (reuse) */ { uint32_t lc_encrypt_type; - /* Once a loop is initialized RO, there is no + /* Once a xloop is initialized RO, there is no * way to change its parameters. */ if (loopcxt_is_readonly(lc) && !(lo_flags & LO_FLAGS_READ_ONLY)) { loopcxt_deinit(lc); - errx(EXIT_FAILURE, _("%s: overlapping read-only loop device exists"), file); + errx(EXIT_FAILURE, _("%s: overlapping read-only xloop device exists"), file); } /* This is no more supported, but check to be safe. */ if (loopcxt_get_encrypt_type(lc, &lc_encrypt_type) == 0 && lc_encrypt_type != LO_CRYPT_NONE) { loopcxt_deinit(lc); - errx(EXIT_FAILURE, _("%s: overlapping encrypted loop device exists"), file); + errx(EXIT_FAILURE, _("%s: overlapping encrypted xloop device exists"), file); } lc->info.lo_flags &= ~LO_FLAGS_AUTOCLEAR; if (loopcxt_ioctl_status(lc)) { loopcxt_deinit(lc); - errx(EXIT_FAILURE, _("%s: failed to re-use loop device"), file); + errx(EXIT_FAILURE, _("%s: failed to re-use xloop device"), file); } return 0; /* success, re-use */ } default: /* error */ loopcxt_deinit(lc); - errx(EXIT_FAILURE, _("failed to inspect loop devices")); + errx(EXIT_FAILURE, _("failed to inspect xloop devices")); return -errno; } } @@ -541,7 +541,7 @@ static int create_loop(struct loopdev_cxt *lc, if (hasdev && !is_loopdev(loopcxt_get_device(lc))) loopcxt_add_device(lc); - /* xlosetup --noverlap /dev/loopN file.img */ + /* xlosetup --noverlap /dev/xloopN file.img */ if (hasdev && nooverlap) { struct loopdev_cxt lc2; @@ -555,8 +555,8 @@ static int create_loop(struct loopdev_cxt *lc, if (rc) { loopcxt_deinit(lc); if (rc > 0) - errx(EXIT_FAILURE, _("%s: overlapping loop device exists"), file); - err(EXIT_FAILURE, _("%s: failed to check for conflicting loop devices"), file); + errx(EXIT_FAILURE, _("%s: overlapping xloop device exists"), file); + err(EXIT_FAILURE, _("%s: failed to check for conflicting xloop devices"), file); } } @@ -568,7 +568,7 @@ static int create_loop(struct loopdev_cxt *lc, * loopcxt struct. */ if (!hasdev && (rc = loopcxt_find_unused(lc))) { - warnx(_("cannot find an unused loop device")); + warnx(_("cannot find an unused xloop device")); break; } if (flags & LOOPDEV_FL_OFFSET) @@ -600,7 +600,7 @@ static int create_loop(struct loopdev_cxt *lc, /* errors */ errpre = hasdev && loopcxt_get_fd(lc) < 0 ? loopcxt_get_device(lc) : file; - warn(_("%s: failed to set up loop device"), errpre); + warn(_("%s: failed to set up xloop device"), errpre); break; } while (hasdev == 0); @@ -838,12 +838,12 @@ int main(int argc, char **argv) } if (!act) { /* - * xlosetup <loopdev> <backing_file> + * xlosetup <xloopdev> <backing_file> */ act = A_CREATE; if (optind >= argc) - errx(EXIT_FAILURE, _("no loop device specified")); + errx(EXIT_FAILURE, _("no xloop device specified")); /* don't use is_loopdev() here, the device does not have exist yet */ if (loopcxt_set_device(&lc, argv[optind])) err(EXIT_FAILURE, _("%s: failed to use device"), @@ -858,7 +858,7 @@ int main(int argc, char **argv) if (act != A_CREATE && (sizelimit || lo_flags || showdev || use_file_fmt_type)) errx(EXIT_FAILURE, - _("the options %s are allowed during loop device setup only"), + _("the options %s are allowed during xloop device setup only"), "--{sizelimit,partscan,read-only,show,type}"); if ((flags & LOOPDEV_FL_OFFSET) && @@ -906,7 +906,7 @@ int main(int argc, char **argv) else errno = errsv; - warn(_("cannot find an unused loop device")); + warn(_("cannot find an unused xloop device")); } else printf("%s\n", loopcxt_get_device(&lc)); break; |