Signed-off-by: Tony Asleson <***@redhat.com>
---
configure.ac | 1 -
tools/Makefile.am | 2 +-
tools/lsmcli/Makefile.am | 9 -
tools/lsmcli/arguments.cpp | 477 -------------------------------------------
tools/lsmcli/arguments.h | 226 --------------------
tools/lsmcli/lsmcli.cpp | 86 --------
tools/lsmcli/lsmcli_func.cpp | 426 --------------------------------------
tools/lsmcli/lsmcli_func.h | 117 -----------
8 files changed, 1 insertion(+), 1343 deletions(-)
delete mode 100644 tools/lsmcli/Makefile.am
delete mode 100644 tools/lsmcli/arguments.cpp
delete mode 100644 tools/lsmcli/arguments.h
delete mode 100644 tools/lsmcli/lsmcli.cpp
delete mode 100644 tools/lsmcli/lsmcli_func.cpp
delete mode 100644 tools/lsmcli/lsmcli_func.h
diff --git a/configure.ac b/configure.ac
index ab25017..c13bc55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,7 +150,6 @@ AC_OUTPUT(libstoragemgmt.pc \
doc/man/lsmd.1 \
doc/doxygen.conf \
tools/Makefile \
- tools/lsmcli/Makefile \
tools/udev/Makefile \
include/Makefile \
include/libstoragemgmt/Makefile \
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d0689f6..b097ed0 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,3 +1,3 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = lsmcli lsmclipy udev
+SUBDIRS = lsmclipy udev
diff --git a/tools/lsmcli/Makefile.am b/tools/lsmcli/Makefile.am
deleted file mode 100644
index d383737..0000000
--- a/tools/lsmcli/Makefile.am
+++ /dev/null
@@ -1,9 +0,0 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include -***@srcdir@/include
-
-noinst_PROGRAMS = lsmcli
-#bin_PROGRAMS = lsmcli
-lsmcli_LDADD = ../../src/libstoragemgmt.la
-lsmcli_SOURCES = lsmcli.cpp \
- arguments.h arguments.cpp \
- lsmcli_func.h lsmcli_func.cpp
-
diff --git a/tools/lsmcli/arguments.cpp b/tools/lsmcli/arguments.cpp
deleted file mode 100644
index 1484c7d..0000000
--- a/tools/lsmcli/arguments.cpp
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#include "arguments.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <iomanip>
-#include <sstream>
-#include <algorithm>
-
-
-namespace LSM {
-
-#define _(text) text
-const char *list_types[] = { LIST_TYPE_VOL, LIST_TYPE_POOL, LIST_TYPE_INIT };
-const std::vector<std::string> listTypes(list_types, list_types + 3);
-
-const char *init_types[] = { INIT_TYPE_WWPN, INIT_TYPE_WWNN, INIT_TYPE_ISCSI,
- INIT_TYPE_HN };
-const std::vector<std::string> initTypes(init_types, init_types + 4);
-
-const char *prov_types[] = { PROV_TYPE_DEFAULT, PROV_TYPE_THIN, PROV_TYPE_FULL};
-const std::vector<std::string> provTypes(prov_types, prov_types + 3);
-
-const char *rep_types[] = { REP_TYPE_SNAPSHOT, REP_TYPE_CLONE, REP_TYPE_COPY, REP_TYPE_MIRROR };
-const std::vector<std::string> repTypes(rep_types, rep_types + 4);
-
-const char *access_types[] = { ACCESS_TYPE_RW, ACCESS_TYPE_RO };
-const std::vector<std::string> accessTypes(access_types, access_types + 2);
-
-lsmInitiatorType Arguments::initiatorType() const
-{
- lsmInitiatorType rc = LSM_INITIATOR_OTHER;
- if( type.value == INIT_TYPE_WWPN ) {
- rc = LSM_INITIATOR_PORT_WWN;
- } else if( type.value == INIT_TYPE_WWNN ) {
- rc = LSM_INITIATOR_NODE_WWN;
- } else if( type.value == INIT_TYPE_ISCSI ) {
- rc = LSM_INITIATOR_ISCSI;
- } else if( type.value == INIT_TYPE_HN ) {
- rc = LSM_INITIATOR_HOSTNAME;
- }
- return rc;
-}
-
-lsmProvisionType Arguments::provisionType() const
-{
- lsmProvisionType rc = LSM_PROVISION_UNKNOWN;
- if( provisioning.value == PROV_TYPE_DEFAULT ) {
- rc = LSM_PROVISION_DEFAULT;
- } else if( provisioning.value == PROV_TYPE_THIN ) {
- rc = LSM_PROVISION_THIN;
- } else if( provisioning.value == PROV_TYPE_FULL) {
- rc = LSM_PROVISION_FULL;
- }
- return rc;
-}
-
-lsmReplicationType Arguments::replicationType() const
-{
- lsmReplicationType rc = LSM_VOLUME_REPLICATE_UNKNOWN;
-
- if( type.value == REP_TYPE_SNAPSHOT ) {
- rc = LSM_VOLUME_REPLICATE_SNAPSHOT;
- } else if ( type.value == REP_TYPE_CLONE) {
- rc = LSM_VOLUME_REPLICATE_CLONE;
- } else if ( type.value == REP_TYPE_COPY) {
- rc = LSM_VOLUME_REPLICATE_COPY;
- } else if ( type.value == REP_TYPE_MIRROR ) {
- rc = LSM_VOLUME_REPLICATE_MIRROR_ASYNC;
- }
- return rc;
-}
-
-lsmAccessType Arguments::accessType() const
-{
- lsmAccessType rc = LSM_VOLUME_ACCESS_NONE;
- if( access.value == ACCESS_TYPE_RW ) {
- rc = LSM_VOLUME_ACCESS_READ_WRITE;
- } else {
- rc = LSM_VOLUME_ACCESS_READ_ONLY;
- }
- return rc;
-}
-
-void syntaxError(const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
- exit(1);
-}
-
-void usage()
-{
- printf(_("Usage: %s [OPTIONS]... [COMAND]...\n"), "lsmcli");
- fputs(_("\
-Manage storage in external storage arrays.\n\
-\n\
-"), stdout);
- fputs(_("\
-Options include:\n\
- -u, --uri uniform resource identifier (LSMCLI_URI) \n\
- -P, --prompt prompt for password (LSMCLI_PASSWORD)\n\
- -H, print sizes in human readable format\n\
- (e.g., MiB, GiB, TiB)\n\
- -t, --terse=SEP print output in terse form with \"SEP\" as a \n\
- record separator\n\
-"), stdout);
-
- fputs(_("\
- --create-volume=NAME requires:\n\
- --size <volume size> Can use M, G, T\n\
- --pool <pool id>\n\
- --provisioning [DEFAULT|THIN|FULL]\n\
- --delete-volume=ID deletes a volume given its volume id\n\
-"), stdout);
- fputs(_("\
- -r, --replicate=VOLUME_ID replicates a volume, requires:\n\
- --type [SNAPSHOT|CLONE|COPY|MIRROR]\n\
- --pool <pool id>\n\
- --name <human name>\n\
- , --resize-volume=VOLUME_ID resizes a volume, requires:\n\
- --size <new size>\n\
-"), stdout);
- fputs(_("\
- -v, --version print version information and exit\n\
- -h, --help print help text\n\n\n\
-Please report bugs to libstoragemgmt-***@lists.sourceforge.net\n\
-"), stdout);
-
- exit(1);
-}
-
-void version()
-{
- printf("lsmcli version %s, built on %s\n\n", "0.01", __DATE__ ", " __TIME__);
- printf("Copyright 2011 Red Hat, Inc.\n");
- exit(0);
-}
-
-static std::string join(std::vector<std::string> s, std::string del)
-{
- std::string rc = "";
-
- for( size_t i = 0; i < s.size(); ++i) {
- rc += s[i];
- if( i + 1 < s.size()) {
- rc +=del;
- }
- }
-
- return rc;
-}
-
-std::string validateDomain( std::string option, std::string value,
- const std::vector<std::string> &domain)
-{
- std::string arg(value);
- std::transform(arg.begin(), arg.end(), arg.begin(), ::toupper);
-
- for( size_t i = 0; i < domain.size(); ++i ) {
- if( arg == domain[i] ) {
- return arg;
- }
- }
- syntaxError("option (%s) with value (%s) not in set [%s]\n", option.c_str(),
- value.c_str(), join(domain, "|").c_str());
-
- return "Never get here!";
-}
-
-void setCommand( Arguments &args, const std::string &cs, commandTypes c,
- std::string value)
-{
- if( args.c != NONE ) {
- syntaxError(" only one command can be specified at a time, "
- "previous is (%s)\n", args.commandStr.c_str());
- } else {
- args.commandStr = cs;
- args.c = c;
- args.commandValue = value;
- }
-}
-
-static struct option long_options[] = {
- /* These options set a flag. */
- {"uri", required_argument, 0, 'u'}, //0
- {"list", required_argument, 0, 'l'}, //1
- {"create-initiator", required_argument, 0, 0}, //2
- {"create-volume", required_argument, 0, 0}, //3
- {"delete-initiator", required_argument, 0, 0}, //4 //Future use
- {"delete-volume", required_argument, 0, 0}, //5
- {"replicate", required_argument, 0, 'r'}, //6
- {"access-grant", required_argument, 0, 0}, //7
- {"access-revoke", required_argument, 0, 0}, //8
- {"terse", required_argument, 0, 0}, //9
- {"help", no_argument, 0, 'h'}, //10
- {"prompt", no_argument, 0, 'P'}, //11
- {"version", no_argument, 0, 'v'}, //12
- {"size", required_argument, 0, 0}, //13
- {"type", required_argument, 0, 0}, //14
- {"provisioning", required_argument, 0, 0}, //15
- {"access", required_argument, 0, 0}, //16
- {"volume", required_argument, 0, 0}, //17
- {"id", required_argument, 0, 0}, //18
- {"pool", required_argument, 0, 0}, //19
- {"name", required_argument, 0, 0}, //20
- {"resize-volume", required_argument, 0, 0}, //21
- {0, 0, 0, 0}
-};
-
-void parseArguments(int argc, char **argv, Arguments &args) {
- int c;
-
- while (1) {
-
- int long_opt_index = 0;
-
- c = getopt_long(argc, argv, "u:PHr:vht:l:",
- long_options, &long_opt_index);
-
- /* Detect the end of the options. */
- if (c == -1)
- break;
-
- switch (c) {
- case 0: {
- /* If this option set a flag, do nothing else now. */
- if (long_options[long_opt_index].flag != 0)
- break;
-
- if( long_opt_index <= REPLICATE ) {
- setCommand(args, long_options[long_opt_index].name,
- (commandTypes)long_opt_index, optarg);
- } else {
- switch (long_opt_index) {
- case (13): {
- uint64_t s = 0;
-
- if( ! sizeArg(optarg, &s) ) {
- syntaxError("--size %s not in the form "
- "<num>|<num>[M|G|T]\n", optarg);
- }
- args.size.set(optarg);
- break;
- }
- case (14): {
- args.type.set(optarg);
- break;
- }
- case (15): {
- args.provisioning.set(optarg);
- break;
- }
- case (16): {
- args.access.set(optarg);
- break;
- }
- case (17): {
- args.volume.set(optarg);
- break;
- }
- case (18): {
- args.id.set(optarg);
- break;
- }
- case (19): {
- args.pool.set(optarg);
- break;
- }
- case (20): {
- args.name.set(optarg);
- break;
- }
- case (21): {
- setCommand(args, long_options[long_opt_index].name,
- (commandTypes)long_opt_index, optarg);
- break;
- }
- }
- }
- break;
- }
- case('u'): {
- args.uri.set(optarg);
- break;
- }
- case 'l': {
- setCommand(args, "l", LIST, validateDomain("-l", optarg,
- listTypes));
- break;
- }
- case 'h': {
- usage();
- break;
- }
- case 'H': {
- args.human.set(true);
- break;
- }
- case 'P': {
- args.prompt.set(true);
- break;
- }
- case 't': {
- args.terse.set(optarg);
- break;
- }
- case 'v': {
- version();
- break;
- }
- case 'r': {
- setCommand(args, "r", REPLICATE, optarg);
- break;
- }
- case '?': {
- break;
- }
- default: {
- syntaxError("Code bug, missing handler for option %c\n", c);
- }
- }
- }
-}
-
-//Everything parsed, lets see if it logically makes sense.
-void requiredArguments( Arguments &args)
-{
- if( args.c == NONE ) {
- syntaxError("No command specified. -h for help\n");
- } else {
- switch ( args.c ) {
- case (CREATE_VOL) : {
- if( args.size.present && args.pool.present &&
- args.provisioning.present ) {
-
- //Verify provisioning
- validateDomain("--provisioning", args.provisioning.value,
- provTypes);
- } else {
- syntaxError("--%s requires --size, --pool and "
- "--provisioning!\n", args.commandStr.c_str());
- }
- break;
- }
-
- case ( REPLICATE ) : {
- if( args.type.present && args.pool.present &&
- args.name.present) {
-
- validateDomain("--type", args.type.value, repTypes);
-
- } else {
- syntaxError("-%s requires --type and --pool and --name \n",
- args.commandStr.c_str());
- }
- break;
- }
- case ( RESIZE_VOLUME ) : {
- if( !args.size.present ) {
- syntaxError("--%s requires --size\n",
- args.commandStr.c_str());
- }
- break;
- }
- case ( NONE ):
- case ( DELETE_VOL ):
- case ( LIST ) : {
- break;
- }
-
- }
-
- //Check other values.
- if( !args.uri.present ) {
- char *uri_env = getenv("LSMCLI_URI");
- if( uri_env ) {
- args.uri.set(uri_env);
- }
- }
-
- if( !args.uri.present ) {
- syntaxError("uri missing, please use -u "
- "or export LSMCLI_URI=<uri>\n");
- }
-
- //Not prompting for password, then check for ENV.
- if( !args.prompt.present ) {
- char *pw = getenv("LSMCLI_PASSWORD");
- if( pw ) {
- args.password.set(std::string(pw));
- }
- } else {
- args.password.set(std::string(getpass("Password: ")));
- }
- }
-}
-
-void processCommandLine( int argc, char **argv, Arguments &args )
-{
- parseArguments(argc, argv, args);
- requiredArguments(args);
-}
-
-int sizeArg(const char *s, uint64_t *size)
-{
- char units = 'M';
- int rc = 0;
-
- if( s != NULL && size != NULL &&
- (2 == sscanf(s,"%"PRIu64"%c", size, &units)) &&
- (units == 'M' || units == 'G' || units == 'T') ) {
-
- if( units == 'M') {
- *size *= MiB;
- } else if (units == 'G') {
- *size *= GiB;
- } else if (units == 'T') {
- *size *= TiB;
- }
- rc = 1;
- }
- return rc;
-}
-
-std::string sizeHuman(bool human, uint64_t size)
-{
- std::string units ="";
- double s = size;
-
- if( human ) {
- if( size >= TiB ) {
- units=" TiB";
- s /= (double)TiB;
-
- } else if( size >= GiB ) {
- units=" GiB";
- s /= (double)GiB;
-
- } else if( size >= MiB ) {
- units=" MiB";
- s /= (double)MiB;
- }
- }
-
- std::ostringstream o;
- if( human && (size >= MiB) ) {
- o << std::setiosflags(std::ios::fixed) << std::setprecision(2) << s;
- } else {
- o << size;
- }
-
- return o.str() + units;
-}
-
-} //Namespace
diff --git a/tools/lsmcli/arguments.h b/tools/lsmcli/arguments.h
deleted file mode 100644
index 367673d..0000000
--- a/tools/lsmcli/arguments.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#ifndef __ARGUMENTS_H
-#define __ARGUMENTS_H
-
-#include <string>
-#include <vector>
-#include <stdint.h>
-#include <libstoragemgmt/libstoragemgmt_types.h>
-
-namespace LSM {
-
-#define LIST_TYPE_VOL "VOLUMES"
-#define LIST_TYPE_POOL "POOLS"
-#define LIST_TYPE_INIT "INITIATORS"
-
-#define INIT_TYPE_WWPN "WWPN"
-#define INIT_TYPE_WWNN "WWNN"
-#define INIT_TYPE_ISCSI "ISCSI"
-#define INIT_TYPE_HN "HOSTNAME"
-
-#define PROV_TYPE_DEFAULT "DEFAULT"
-#define PROV_TYPE_THIN "THIN"
-#define PROV_TYPE_FULL "FULL"
-
-#define REP_TYPE_SNAPSHOT "SNAPSHOT"
-#define REP_TYPE_CLONE "CLONE"
-#define REP_TYPE_COPY "COPY"
-#define REP_TYPE_MIRROR "MIRROR"
-
-#define ACCESS_TYPE_RW "RW"
-#define ACCESS_TYPE_RO "RO"
-
-template <class Type>
-class Arg {
-public:
- bool present;
- Type value;
-
- Arg() : present(false) {
- }
-
- void set(Type t) {
- present = true;
- value = t;
- }
-};
-
-/**
- * Enumerated commands. Note: make sure they match array index for long_options
- */
-typedef enum {
- NONE = -1,
- LIST = 1,
- //CREATE_INIT = 2,
- CREATE_VOL = 3,
- //DELETE_INIT = 4,
- DELETE_VOL = 5,
- REPLICATE = 6,
- //ACCESS_GRANT = 7,
- //ACCESS_REVOKE = 8,
- RESIZE_VOLUME = 21,
-} commandTypes;
-
-/**
- * Class the encapsulates the command line arguments.
- */
-class Arguments {
-public:
- Arguments():c(NONE){}
-
- /**
- * Uri.
- */
- Arg<std::string> uri;
-
- /**
- * Prompt for password
- */
- Arg<bool> prompt;
-
- /**
- * Output sizes as human
- */
- Arg<bool> human;
-
- /**
- * Use terse output
- */
- Arg<std::string> terse;
-
- /**
- * Generic identifier, needs command for context.
- */
- Arg<std::string> id;
-
- /**
- * Generic type, needs command for context.
- */
- Arg<std::string> type;
-
- /**
- * Generic name, needs command for context.
- */
- Arg<std::string> name;
-
- /**
- * Size specifier, needs command for context.
- */
- Arg<std::string> size;
-
- /**
- * Pool specifier, needs command for context.
- */
- Arg<std::string> pool;
-
- /**
- * Provision specifier, needs command for context.
- */
- Arg<std::string> provisioning;
-
- /**
- * Access specifier, needs command for context.
- */
- Arg<std::string> access;
-
- /**
- * Connection password, needs command for context.
- */
- Arg<std::string> password;
-
- /**
- * Volume specifier, needs command for context.
- */
- Arg<std::string> volume;
-
- /**
- * Actual command to execute
- */
- commandTypes c;
-
- /**
- * String representation of command.
- */
- std::string commandStr;
-
- /**
- * Command value.
- */
- std::string commandValue;
-
- /**
- * Convert string representation to enum.
- * @return lsmInitiatorType value
- */
- lsmInitiatorType initiatorType() const;
-
- /**
- * Convert string representation to enum.
- * @return lsmProvisionType value
- */
- lsmProvisionType provisionType() const;
-
- /**
- * Convert string representation to enum.
- * @return lsmReplicationType value.
- */
- lsmReplicationType replicationType() const;
-
- /**
- * Convert string representation to enum.
- * @return lsmAccessType value.
- */
- lsmAccessType accessType() const;
-};
-
-/**
- * Processes the command line arguments.
- * Note: This function will exit() on missing/bad arguments.
- * @param argc Command line argument count
- * @param argv Arguments
- * @param args Class which holds the parsed arguments.
- */
-void processCommandLine( int argc, char **argv, Arguments &args );
-
-
-const uint64_t MiB = 1048576; //2**20
-const uint64_t GiB = 1073741824; //2**30
-const uint64_t TiB = 1099511627776ULL; //2**40
-
-/**
- * Validates and returns the value of size that the user supplied
- * @param s String in the form [0-9]+[MGT]
- * @param[out] size Size in bytes.
- * @return 1 if parsed OK, else 0.
- */
-int sizeArg(const char* s, uint64_t *size);
-
-/**
- * Returns a string representation of a size
- * @param human True use human readable size.
- * @param size Size to represent
- * @return Size represented as a string.
- */
-std::string sizeHuman(bool human, uint64_t size);
-
-} //namespace
-
-#endif
diff --git a/tools/lsmcli/lsmcli.cpp b/tools/lsmcli/lsmcli.cpp
deleted file mode 100644
index 0b3b6a3..0000000
--- a/tools/lsmcli/lsmcli.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#include <iostream>
-#include <string>
-#include <stdio.h>
-#include "arguments.h"
-#include "lsmcli_func.h"
-#include <libstoragemgmt/libstoragemgmt.h>
-
-void debug_plugin(void)
-{
- char *debug = getenv("LSM_DEBUG_PLUGIN");
- if( debug ) {
- printf("Attach debugger to plug-in, press any key when ready...");
- ::getchar();
- }
-}
-
-
-int main(int argc, char *argv[])
-{
- lsmConnect *c = NULL;
- lsmErrorPtr e = NULL;
-
- LSM::Arguments a;
- LSM::processCommandLine(argc, argv, a);
-
- int main_rc = 0;
- int lib_rc = lsmConnectPassword(a.uri.value.c_str(),
- a.password.value.c_str(), &c, 30000, &e,
- LSM_FLAG_RSVD);
-
- if( LSM_ERR_OK == lib_rc ) {
- debug_plugin();
- switch( a.c ) {
- case (LSM::LIST) : {
- main_rc = list(a,c);
- break;
- }
- case (LSM::CREATE_VOL) : {
- main_rc = createVolume(a,c);
- break;
- }
- case (LSM::DELETE_VOL) : {
- main_rc = deleteVolume(a,c);
- break;
- }
- case (LSM::REPLICATE) : {
- main_rc = replicateVolume(a,c);
- break;
- }
- case (LSM::RESIZE_VOLUME) : {
- main_rc = resizeVolume(a,c);
- break;
- }
- case (LSM::NONE): {
- break;
- }
- }
-
- lib_rc = lsmConnectClose(c, LSM_FLAG_RSVD);
- if( LSM_ERR_OK != lib_rc ) {
- printf("Error on close %d!\n", lib_rc);
- }
- } else {
- dumpError(lib_rc, e);
- }
- return main_rc;
-}
\ No newline at end of file
diff --git a/tools/lsmcli/lsmcli_func.cpp b/tools/lsmcli/lsmcli_func.cpp
deleted file mode 100644
index 323eaa4..0000000
--- a/tools/lsmcli/lsmcli_func.cpp
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-#include "lsmcli_func.h"
-#include "arguments.h"
-#include <stdio.h>
-#include <assert.h>
-#include <stdint.h>
-#define __STDC_FORMAT_MACROS /* To use PRIu64 */
-#include <inttypes.h>
-#include <unistd.h>
-
-lsmInitiator *getInitiator(lsmConnect *c, std::string initId);
-
-void printVolume(const LSM::Arguments &a, lsmVolume *v)
-{
- const char *id = lsmVolumeIdGet(v);
- const char *name = lsmVolumeNameGet(v);
- const char *vpd = lsmVolumeVpd83Get(v);
- uint64_t block_size = lsmVolumeBlockSizeGet(v);
- uint64_t block_num = lsmVolumeNumberOfBlocksGet(v);
- uint32_t status = lsmVolumeOpStatusGet(v);
- uint64_t size = block_size * block_num;
- std::string s = LSM::sizeHuman(a.human.present, size);
-
- if( a.terse.present ) {
- const char *sep = a.terse.value.c_str();
-
- printf("%s%s%s%s%s%s%"PRIu64"%s%"PRIu64"%s%u%s%s\n", id, sep, name,
- sep, vpd, sep, block_size, sep, block_num, sep,
- status, sep, s.c_str());
- } else {
- printf("%s %-40s\t%s %-8"PRIu64"\t%-17"PRIu64"\t%u\t%20s\n", id, name,
- vpd, block_size, block_num, status, s.c_str());
- }
-}
-
-void printInitiator(const LSM::Arguments &a, lsmInitiator *i)
-{
- const char format[] = "%-40s%-16s%-5d\n";
- const char *sep = NULL;
-
- const char *id = lsmInitiatorIdGet(i);
- const char *name = lsmInitiatorNameGet(i);
- lsmInitiatorType type = lsmInitiatorTypeGet(i);
-
- if( a.terse.present ) {
- sep = a.terse.value.c_str();
- }
-
- if( a.terse.present ) {
- printf("%s%s%s%s%d\n", id, sep, name, sep, type);
- } else {
- printf(format, id, name, type);
- }
-}
-
-int waitForJob(int cmd_rc, lsmConnect *c, char *job,
- const LSM::Arguments &a, lsmVolume **vol)
-{
- lsmVolume *new_volume = NULL;
- int rc = cmd_rc;
- //Check to see if we are done!
- if( LSM_ERR_OK != rc ) {
- if ( LSM_ERR_JOB_STARTED == rc ) {
- //We have a job to wait for.
- lsmJobStatus status;
- uint8_t percent = 0;
-
- do {
- usleep(10000);
- rc = lsmJobStatusVolumeGet(c, job, &status, &percent, &new_volume, 0);
- //printf("job = %s, status %d, percent %d\n", job, status, percent);
- } while ( (LSM_JOB_INPROGRESS == status) && (LSM_ERR_OK == rc) );
-
- if( vol != NULL) {
- *vol = new_volume;
- } else {
- if( new_volume ) {
- lsmVolumeRecordFree(new_volume);
- new_volume = NULL;
- }
- }
-
- if( (LSM_ERR_OK == rc) && (LSM_JOB_COMPLETE == status) && new_volume ) {
- printVolume(a, new_volume);
- } else {
- printf("RC = %d, job = %s, status %d, percent %d\n", rc, job, status, percent);
- }
-
- //Clean up the job
- int jf = lsmJobFree(c, &job, 0);
- if( LSM_ERR_OK != jf ) {
- printf("lsmJobFree rc= %d\n", jf);
- }
- assert(LSM_ERR_OK == jf);
-
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- } else {
- if( vol ) {
- printVolume(a, *vol);
- }
- }
-
- if( vol ) {
- lsmVolumeRecordFree(*vol);
- }
-
- return rc;
-}
-
-void dumpError(int ec, lsmErrorPtr e)
-{
- printf("Error occurred: %d\n", ec);
-
- if( e ) {
- printf("Msg: %s\n", lsmErrorGetMessage(e));
- printf("Exception: %s\n", lsmErrorGetException(e));
- lsmErrorFree(e);
- }
-}
-
-//NOTE: Re-factor these three functions as they are too similar and could be
-//consolidated.
-static int listVolumes(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmVolume **vol = NULL;
- uint32_t num_vol = 0;
-
- rc = lsmVolumeList(c, &vol, & num_vol, 0);
-
- if( rc == LSM_ERR_OK ) {
- uint32_t i;
-
- if( !a.terse.present ) {
- printf("ID Name vpd83 "
- " bs #blocks status size\n");
- }
-
- for( i = 0; i < num_vol; ++i ) {
- printVolume(a, vol[i]);
- }
-
- lsmVolumeRecordFreeArray(vol, num_vol);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return rc;
-}
-
-static int listInitiators(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmInitiator **init = NULL;
- uint32_t num_init = 0;
- const char format[] = "%-40s%-16s%-5s\n";
-
- rc = lsmInitiatorList(c, &init, &num_init, 0);
-
- if( LSM_ERR_OK == rc ) {
- uint32_t i = 0;
-
- if( !a.terse.present ) {
- printf(format, "ID", "Name", "Type");
- }
-
- for( i = 0; i < num_init; ++i ) {
- printInitiator(a,init[i]);
- }
- lsmInitiatorRecordFreeArray(init,num_init);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return rc;
-}
-
-static int listPools(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmPool **pool = NULL;
- uint32_t num_pool = 0;
- const char *sep = NULL;
-
- rc = lsmPoolList(c, &pool, &num_pool, 0);
-
- if( LSM_ERR_OK == rc ) {
- uint32_t i = 0;
-
- if( a.terse.present ) {
- sep = a.terse.value.c_str();
- } else {
- printf("ID Name"
- " Total space "
- " Free space\n");
- }
-
- for( i = 0; i < num_pool; ++i ) {
- const char *id = lsmPoolIdGet(pool[i]);
- const char *name = lsmPoolNameGet(pool[i]);
- uint64_t total = lsmPoolTotalSpaceGet(pool[i]);
- uint64_t free = lsmPoolFreeSpaceGet(pool[i]);
-
- if( a.terse.present ) {
- printf("%s%s%s%s%s%s%s\n", id, sep, name, sep,
- LSM::sizeHuman(a.human.present, total).c_str(), sep,
- LSM::sizeHuman(a.human.present, free).c_str());
- } else {
- printf("%s\t%s\t%32s\t%32s\n", id, name,
- LSM::sizeHuman(a.human.present, total).c_str(),
- LSM::sizeHuman(a.human.present, free).c_str() );
- }
- }
-
- lsmPoolRecordFreeArray(pool,num_pool);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return rc;
-}
-
-int list(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- if( a.commandValue == LIST_TYPE_VOL ) {
- rc = listVolumes(a,c);
- } else if ( a.commandValue == LIST_TYPE_INIT ) {
- rc = listInitiators(a,c);
- } else if ( a.commandValue == LIST_TYPE_POOL ) {
- rc = listPools(a,c);
- }
-
- return rc;
-}
-
-//Re-factor these next three functions as they are similar.
-lsmPool *getPool(lsmConnect *c, std::string poolId)
-{
- int rc = 0;
- lsmPool *p = NULL;
- lsmPool **pool = NULL;
- uint32_t num_pool = 0;
- uint32_t i = 0;
-
- rc = lsmPoolList(c, &pool, &num_pool, 0);
-
- if( LSM_ERR_OK == rc ) {
- for( i = 0; i < num_pool; ++i ) {
- if( poolId == lsmPoolIdGet(pool[i])) {
- p = lsmPoolRecordCopy(pool[i]);
- break;
- }
- }
- lsmPoolRecordFreeArray(pool, num_pool);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return p;
-}
-
-lsmVolume *getVolume(lsmConnect *c, std::string volumeId)
-{
- int rc = 0;
- lsmVolume *p = NULL;
- lsmVolume **vol = NULL;
- uint32_t num_vol = 0;
- uint32_t i = 0;
-
- rc = lsmVolumeList(c, &vol, &num_vol, 0);
-
- if( LSM_ERR_OK == rc ) {
- for( i = 0; i < num_vol; ++i ) {
- if( volumeId == lsmVolumeIdGet(vol[i])) {
- p = lsmVolumeRecordCopy(vol[i]);
- break;
- }
- }
- lsmVolumeRecordFreeArray(vol, num_vol);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return p;
-}
-
-lsmInitiator *getInitiator(lsmConnect *c, std::string initId)
-{
- int rc = 0;
- lsmInitiator *p = NULL;
- lsmInitiator **inits = NULL;
- uint32_t num_inits = 0;
- uint32_t i = 0;
-
- rc = lsmInitiatorList(c, &inits, &num_inits, 0);
-
- if( LSM_ERR_OK == rc ) {
- for( i = 0; i < num_inits; ++i ) {
- if( initId == lsmInitiatorIdGet(inits[i])) {
- p = lsmInitiatorRecordCopy(inits[i]);
- break;
- }
- }
- lsmInitiatorRecordFreeArray(inits, num_inits);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return p;
-}
-
-int createVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmVolume *vol = NULL;
- char *job = NULL;
- uint64_t size = 0;
- lsmPool *pool = NULL;
-
- //Get the pool of interest
- pool = getPool(c, a.pool.value);
- if( pool ) {
-
- LSM::sizeArg(a.size.value.c_str(), &size);
-
- rc = lsmVolumeCreate(c,pool, a.commandValue.c_str(),
- size, a.provisionType(), &vol, &job, 0);
-
- rc = waitForJob(rc, c, job, a, &vol);
-
- lsmPoolRecordFree(pool);
- } else {
- printf("Pool with id= %s not found!\n", a.pool.value.c_str());
- }
- return rc;
-}
-
-int deleteVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- char *job = NULL;
- //Get the volume pointer to the record in question to delete.
- lsmVolume *vol = getVolume(c, a.commandValue);
-
- if( vol ) {
- rc = lsmVolumeDelete(c, vol, &job, 0);
- rc = waitForJob(rc, c, job, a);
- } else {
- printf("Volume with id= %s not found!\n", a.commandValue.c_str());
- }
- return rc;
-}
-
-int replicateVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- char *job = NULL;
- lsmVolume *newVol = NULL;
- lsmVolume *vol = getVolume(c, a.commandValue);
- lsmPool *pool = getPool(c, a.pool.value);
-
-
- if( vol && pool ) {
- rc = lsmVolumeReplicate(c, pool, a.replicationType(), vol,
- a.name.value.c_str(), &newVol, &job, 0);
- rc = waitForJob(rc, c, job, a, &newVol);
- } else {
- if( !vol ) {
- printf("Volume with id= %s not found!\n", a.commandValue.c_str());
- }
-
- if( !pool ) {
- printf("Pool with id= %s not found!\n", a.pool.value.c_str());
- }
- }
-
- if( vol ) {
- lsmVolumeRecordFree(vol);
- vol = NULL;
- }
-
- if( pool ) {
- lsmPoolRecordFree(pool);
- pool = NULL;
- }
-
- return rc;
-}
-
-int resizeVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- char *job = NULL;
- uint64_t size = 0;
- lsmVolume *newVol = NULL;
- lsmVolume *vol = getVolume(c, a.commandValue);
-
- LSM::sizeArg(a.size.value.c_str(), &size);
-
- if( vol ) {
- rc = lsmVolumeResize(c, vol, size, &newVol, &job, 0);
- rc = waitForJob(rc, c, job, a, &newVol);
- } else {
- printf("Volume with id= %s not found!\n", a.commandValue.c_str());
- }
-
- if( vol ) {
- lsmVolumeRecordFree(vol);
- vol = NULL;
- }
- return rc;
-}
diff --git a/tools/lsmcli/lsmcli_func.h b/tools/lsmcli/lsmcli_func.h
deleted file mode 100644
index 840b773..0000000
--- a/tools/lsmcli/lsmcli_func.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#ifndef _LSMCLI_FUNC_H
-#define _LSMCLI_FUNC_H
-
-#include "arguments.h"
-#include <libstoragemgmt/libstoragemgmt.h>
-
-/**
- * Used to wait for a job to complete.
- * @param cmd_rc The return code of the library call that may have a job
- * @param c Connection
- * @param job Job id
- * @param a Command line arguments
- * @param vol New volume to print out.
- * @return LSM_ERR_OK on success else error reason.
- */
-int waitForJob(int cmd_rc, lsmConnect *c, char *job,
- const LSM::Arguments &a, lsmVolume **vol = NULL);
-
-/**
- * Dumps error information to stdout.
- * @param ec Error code
- * @param e Error record.
- */
-void dumpError(int ec, lsmErrorPtr e);
-
-/**
- * Dumps Volumes, initiators, pools to stdout.
- * @param a Command line arguments.
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int list(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Creates an initiator to use for access granting.
- * @param a Command Line arguments
- * @param c Connection.
- * @return LSM_ERR_OK on success, else error reason.
- */
-int createInit(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Deletes an initiator
- * @param a Command line arguments.
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int deleteInit(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Creates a volume
- * @param a Command line arguments.
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int createVolume(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Deletes a volume
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int deleteVolume(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Replicates a volume.
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int replicateVolume(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Allows an initiator to use a volume.
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int accessGrant(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Revokes access for an initiator to a volume.
- * @param a Command line arguments.
- * @param c Connection.
- * @return LSM_ERR_OK on success, else error reason.
- */
-int accessRevoke(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Resize an existing volume.
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int resizeVolume(const LSM::Arguments &a, lsmConnect *c);
-
-#endif
\ No newline at end of file
--
1.8.2.1