mirror of
https://github.com/gluster/gluster-block.git
synced 2026-02-06 06:45:30 +01:00
Currently, on each targetcli create call, rtslib will rebuild its bs_cache, so as the /sys/kernel/config/target/core dir gets more entries this takes longer and longer to scan. Hence using repetitive targetcli in the block create for creating iqn, backend, setting acls, setting globals will induce too much delay in block create. As the number of blocks on the node increases, the delay will be too longer. This does not happen if we open targetcli in interactive mode and just do multiple create commands form it, since the bs_cache is build once. Read More: https://goo.gl/8aYT38 Change-Id: I2be78a748e013f253ce8f99746989a1cf735a56f Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
343 lines
5.9 KiB
C
343 lines
5.9 KiB
C
/*
|
|
Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
|
|
This file is part of gluster-block.
|
|
|
|
This file is licensed to you under your choice of the GNU Lesser
|
|
General Public License, version 3 or any later version (LGPLv3 or
|
|
later), or the GNU General Public License, version 2 (GPLv2), in all
|
|
cases as published by the Free Software Foundation.
|
|
*/
|
|
|
|
|
|
# include <dirent.h>
|
|
# include <sys/stat.h>
|
|
|
|
# include "utils.h"
|
|
# include "config.h"
|
|
|
|
|
|
struct gbConf gbConf = {GB_LOG_INFO, GB_LOGDIR, '\0', '\0', '\0', '\0'};
|
|
|
|
const char *argp_program_version = "" \
|
|
PACKAGE_NAME" ("PACKAGE_VERSION")" \
|
|
"\nRepository rev: https://github.com/gluster/gluster-block.git\n" \
|
|
"Copyright (c) 2016 Red Hat, Inc. <https://redhat.com/>\n" \
|
|
"gluster-block comes with ABSOLUTELY NO WARRANTY.\n" \
|
|
"It is licensed to you under your choice of the GNU Lesser\n" \
|
|
"General Public License, version 3 or any later version (LGPLv3\n" \
|
|
"or later), or the GNU General Public License, version 2 (GPLv2),\n"\
|
|
"in all cases as published by the Free Software Foundation.";
|
|
|
|
|
|
int
|
|
glusterBlockCLIOptEnumParse(const char *opt)
|
|
{
|
|
int i;
|
|
|
|
|
|
if (!opt) {
|
|
return GB_CLI_OPT_MAX;
|
|
}
|
|
|
|
for (i = 0; i < GB_CLI_OPT_MAX; i++) {
|
|
if (!strcmp(opt, gbCliCmdlineOptLookup[i])) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
|
|
int
|
|
glusterBlockDaemonOptEnumParse(const char *opt)
|
|
{
|
|
int i;
|
|
|
|
|
|
if (!opt) {
|
|
return GB_DAEMON_OPT_MAX;
|
|
}
|
|
|
|
for (i = 0; i < GB_DAEMON_OPT_MAX; i++) {
|
|
/* clip '--' from option */
|
|
while (*opt == '-') {
|
|
opt++;
|
|
}
|
|
if (!strcmp(opt, gbDaemonCmdlineOptLookup[i])) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
|
|
int
|
|
blockLogLevelEnumParse(const char *opt)
|
|
{
|
|
int i;
|
|
|
|
|
|
if (!opt) {
|
|
return GB_LOG_MAX;
|
|
}
|
|
|
|
for (i = 0; i < GB_LOG_MAX; i++) {
|
|
if (!strcmp(opt, LogLevelLookup[i])) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
|
|
int
|
|
blockMetaKeyEnumParse(const char *opt)
|
|
{
|
|
int i;
|
|
|
|
|
|
if (!opt) {
|
|
return GB_METAKEY_MAX;
|
|
}
|
|
|
|
for (i = 0; i < GB_METAKEY_MAX; i++) {
|
|
if (!strcmp(opt, MetakeyLookup[i])) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
|
|
int
|
|
blockMetaStatusEnumParse(const char *opt)
|
|
{
|
|
int i;
|
|
|
|
|
|
if (!opt) {
|
|
return GB_METASTATUS_MAX;
|
|
}
|
|
|
|
for (i = 0; i < GB_METASTATUS_MAX; i++) {
|
|
if (!strcmp(opt, MetaStatusLookup[i])) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
int blockRemoteCreateRespEnumParse(const char *opt)
|
|
{
|
|
int i;
|
|
|
|
|
|
if (!opt) {
|
|
return GB_REMOTE_CREATE_RESP_MAX;
|
|
}
|
|
|
|
for (i = 0; i < GB_REMOTE_CREATE_RESP_MAX; i++) {
|
|
if (strstr(opt, RemoteCreateRespLookup[i])) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
|
|
/* On any failure return, epoch atleast */
|
|
void
|
|
logTimeNow(char *buf, size_t bufSize)
|
|
{
|
|
struct tm tm;
|
|
struct timeval tv;
|
|
|
|
|
|
if (gettimeofday (&tv, NULL) < 0) {
|
|
goto out;
|
|
}
|
|
|
|
if (tv.tv_sec && gmtime_r(&tv.tv_sec, &tm) != NULL) {
|
|
strftime (buf, bufSize, "%Y-%m-%d %H:%M:%S", &tm);
|
|
snprintf (buf + strlen(buf), bufSize - strlen(buf), ".%06ld", tv.tv_usec);
|
|
return;
|
|
}
|
|
|
|
out:
|
|
snprintf(buf, bufSize, "%lu", (unsigned long)time(NULL));
|
|
return;
|
|
}
|
|
|
|
|
|
static bool
|
|
glusterBlockLogdirCreate(void)
|
|
{
|
|
DIR* dir = opendir(gbConf.logDir);
|
|
|
|
|
|
if (dir) {
|
|
closedir(dir);
|
|
} else if (errno == ENOENT) {
|
|
if (mkdir(gbConf.logDir, 0755) == -1) {
|
|
fprintf(stderr, "mkdir(%s) failed (%s)", gbConf.logDir, strerror (errno));
|
|
return 0; /* False */
|
|
}
|
|
} else {
|
|
fprintf(stderr, "opendir(%s) failed (%s)", gbConf.logDir, strerror (errno));
|
|
return 0; /* False */
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
int
|
|
initLogging(void)
|
|
{
|
|
char *logDir = NULL;
|
|
|
|
|
|
logDir = getenv("GB_LOGDIR");
|
|
if (!logDir) {
|
|
logDir = GB_LOGDIR;
|
|
}
|
|
|
|
if (strlen(logDir) > PATH_MAX - GB_MAX_LOGFILENAME) {
|
|
fprintf(stderr, "strlen of logDir Path > PATH_MAX: %s\n", logDir);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
/* set logfile paths */
|
|
snprintf(gbConf.logDir, PATH_MAX,
|
|
"%s", logDir);
|
|
snprintf(gbConf.daemonLogFile, PATH_MAX,
|
|
"%s/gluster-blockd.log", logDir);
|
|
snprintf(gbConf.cliLogFile, PATH_MAX,
|
|
"%s/gluster-block-cli.log", logDir);
|
|
snprintf(gbConf.gfapiLogFile, PATH_MAX,
|
|
"%s/gluster-block-gfapi.log", logDir);
|
|
snprintf(gbConf.configShellLogFile, PATH_MAX,
|
|
"%s/gluster-block-configshell.log", logDir);
|
|
|
|
if(!glusterBlockLogdirCreate()) {
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int
|
|
gbRunnerExitStatus(int exitStatus)
|
|
{
|
|
if (!WIFEXITED(exitStatus)) {
|
|
return -1;
|
|
}
|
|
|
|
return WEXITSTATUS(exitStatus);
|
|
}
|
|
|
|
|
|
int
|
|
gbRunner(char *cmd)
|
|
{
|
|
int childExitStatus;
|
|
|
|
|
|
childExitStatus = system(cmd);
|
|
|
|
return gbRunnerExitStatus(childExitStatus);
|
|
}
|
|
|
|
|
|
int
|
|
gbAlloc(void *ptrptr, size_t size,
|
|
const char *filename, const char *funcname, size_t linenr)
|
|
{
|
|
*(void **)ptrptr = calloc(1, size);
|
|
|
|
if (*(void **)ptrptr == NULL) {
|
|
errno = ENOMEM;
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int
|
|
gbAllocN(void *ptrptr, size_t size, size_t count,
|
|
const char *filename, const char *funcname, size_t linenr)
|
|
{
|
|
*(void**)ptrptr = calloc(count, size);
|
|
|
|
if (*(void**)ptrptr == NULL) {
|
|
errno = ENOMEM;
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int
|
|
gbReallocN(void *ptrptr, size_t size, size_t count,
|
|
const char *filename, const char *funcname, size_t linenr)
|
|
{
|
|
void *tmp;
|
|
|
|
|
|
if (xalloc_oversized(count, size)) {
|
|
errno = ENOMEM;
|
|
return -1;
|
|
}
|
|
tmp = realloc(*(void**)ptrptr, size * count);
|
|
if (!tmp && ((size * count) != 0)) {
|
|
errno = ENOMEM;
|
|
return -1;
|
|
}
|
|
*(void**)ptrptr = tmp;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
void
|
|
gbFree(void *ptrptr)
|
|
{
|
|
int save_errno = errno;
|
|
|
|
|
|
if(*(void**)ptrptr == NULL) {
|
|
return;
|
|
}
|
|
|
|
free(*(void**)ptrptr);
|
|
*(void**)ptrptr = NULL;
|
|
errno = save_errno;
|
|
}
|
|
|
|
|
|
int
|
|
gbStrdup(char **dest, const char *src,
|
|
const char *filename, const char *funcname, size_t linenr)
|
|
{
|
|
*dest = NULL;
|
|
|
|
if (!src) {
|
|
return 0;
|
|
}
|
|
|
|
if (!(*dest = strdup(src))) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|