50dc83
From b402b89f71a3ebabca24c459f106af1f9610939a Mon Sep 17 00:00:00 2001
50dc83
From: Anuradha Talur <atalur@commvault.com>
50dc83
Date: Fri, 30 Nov 2018 11:23:07 -0800
50dc83
Subject: [PATCH 154/169] cloudsync/cvlt: Cloudsync plugin for commvault store
50dc83
50dc83
backport of: https://review.gluster.org/#/c/glusterfs/+/21771/
50dc83
50dc83
> Change-Id: Icbe53e78e9c4f6699c7a26a806ef4b14b39f5019
50dc83
> updates: bz#1642168
50dc83
> Signed-off-by: Anuradha Talur <atalur@commvault.com>
50dc83
50dc83
Change-Id: Ib543605daa51fa1cfe77ed475390a30ef14e6452
50dc83
Signed-off-by: Susant Palai <spalai@redhat.com>
50dc83
Reviewed-on: https://code.engineering.redhat.com/gerrit/172194
50dc83
Tested-by: RHGS Build Bot <nigelb@redhat.com>
50dc83
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
50dc83
---
50dc83
 configure.ac                                       |  13 +
50dc83
 glusterfs.spec.in                                  |   1 +
50dc83
 libglusterfs/src/glusterfs/glfs-message-id.h       |   1 +
50dc83
 .../src/cloudsync-plugins/src/Makefile.am          |   6 +-
50dc83
 .../src/cloudsync-plugins/src/cvlt/Makefile.am     |   3 +
50dc83
 .../src/cloudsync-plugins/src/cvlt/src/Makefile.am |  12 +
50dc83
 .../cloudsync-plugins/src/cvlt/src/archivestore.h  | 203 +++++
50dc83
 .../cloudsync-plugins/src/cvlt/src/cvlt-messages.h |  30 +
50dc83
 .../src/cvlt/src/libcloudsynccvlt.sym              |   1 +
50dc83
 .../src/cvlt/src/libcvlt-mem-types.h               |  19 +
50dc83
 .../src/cloudsync-plugins/src/cvlt/src/libcvlt.c   | 842 +++++++++++++++++++++
50dc83
 .../src/cloudsync-plugins/src/cvlt/src/libcvlt.h   |  84 ++
50dc83
 xlators/features/cloudsync/src/cloudsync.c         |   6 +-
50dc83
 xlators/mgmt/glusterd/src/glusterd-volume-set.c    |  10 +-
50dc83
 14 files changed, 1228 insertions(+), 3 deletions(-)
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/Makefile.am
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/Makefile.am
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/archivestore.h
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/cvlt-messages.h
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcloudsynccvlt.sym
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt-mem-types.h
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.c
50dc83
 create mode 100644 xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.h
50dc83
50dc83
diff --git a/configure.ac b/configure.ac
50dc83
index 0e11d4c..f597b86 100644
50dc83
--- a/configure.ac
50dc83
+++ b/configure.ac
50dc83
@@ -170,6 +170,8 @@ AC_CONFIG_FILES([Makefile
50dc83
                 xlators/features/cloudsync/src/cloudsync-plugins/src/Makefile
50dc83
                 xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/Makefile
50dc83
                 xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/Makefile
50dc83
+                xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/Makefile
50dc83
+                xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/Makefile
50dc83
                 xlators/playground/Makefile
50dc83
                 xlators/playground/template/Makefile
50dc83
                 xlators/playground/template/src/Makefile
50dc83
@@ -937,6 +939,17 @@ AM_CONDITIONAL([BUILD_AMAZONS3_PLUGIN], [test "x$HAVE_AMAZONS3" = "xyes"])
50dc83
 if test "x$HAVE_AMAZONS3" = "xyes";then
50dc83
    BUILD_CLOUDSYNC="yes"
50dc83
 fi
50dc83
+BUILD_CVLT_PLUGIN="no"
50dc83
+case $host_os in
50dc83
+#enable cvlt plugin only for linux platforms
50dc83
+     linux*)
50dc83
+       BUILD_CVLT_PLUGIN="yes"
50dc83
+       BUILD_CLOUDSYNC="yes"
50dc83
+       ;;
50dc83
+     *)
50dc83
+       ;;
50dc83
+esac
50dc83
+AM_CONDITIONAL([BUILD_CVLT_PLUGIN], [test "x$BUILD_CVLT_PLUGIN" = "xyes"])
50dc83
 AM_CONDITIONAL([BUILD_CLOUDSYNC], [test "x$BUILD_CLOUDSYNC" = "xyes"])
50dc83
 dnl end cloudsync section
50dc83
 
50dc83
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
50dc83
index ed58356..85e75f2 100644
50dc83
--- a/glusterfs.spec.in
50dc83
+++ b/glusterfs.spec.in
50dc83
@@ -1199,6 +1199,7 @@ exit 0
50dc83
 %files cloudsync-plugins
50dc83
 %dir %{_libdir}/glusterfs/%{version}%{?prereltag}/cloudsync-plugins
50dc83
      %{_libdir}/glusterfs/%{version}%{?prereltag}/cloudsync-plugins/cloudsyncs3.so
50dc83
+     %{_libdir}/glusterfs/%{version}%{?prereltag}/cloudsync-plugins/cloudsynccvlt.so
50dc83
 
50dc83
 %files devel
50dc83
 %dir %{_includedir}/glusterfs
50dc83
diff --git a/libglusterfs/src/glusterfs/glfs-message-id.h b/libglusterfs/src/glusterfs/glfs-message-id.h
50dc83
index 001f4ab..a1a16ca 100644
50dc83
--- a/libglusterfs/src/glusterfs/glfs-message-id.h
50dc83
+++ b/libglusterfs/src/glusterfs/glfs-message-id.h
50dc83
@@ -93,6 +93,7 @@ enum _msgid_comp {
50dc83
     GLFS_MSGID_COMP(TEMPLATE, 1),
50dc83
     GLFS_MSGID_COMP(UTIME, 1),
50dc83
     GLFS_MSGID_COMP(SNAPVIEW_SERVER, 1),
50dc83
+    GLFS_MSGID_COMP(CVLT, 1),
50dc83
     /* --- new segments for messages goes above this line --- */
50dc83
 
50dc83
     GLFS_MSGID_END
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/Makefile.am b/xlators/features/cloudsync/src/cloudsync-plugins/src/Makefile.am
50dc83
index 4deefb6..fb6b058 100644
50dc83
--- a/xlators/features/cloudsync/src/cloudsync-plugins/src/Makefile.am
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/Makefile.am
50dc83
@@ -2,6 +2,10 @@ if BUILD_AMAZONS3_PLUGIN
50dc83
   AMAZONS3_DIR = cloudsyncs3
50dc83
 endif
50dc83
 
50dc83
-SUBDIRS = ${AMAZONS3_DIR}
50dc83
+if BUILD_CVLT_PLUGIN
50dc83
+  CVLT_DIR = cvlt
50dc83
+endif
50dc83
+
50dc83
+SUBDIRS = ${AMAZONS3_DIR} ${CVLT_DIR}
50dc83
 
50dc83
 CLEANFILES =
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/Makefile.am b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/Makefile.am
50dc83
new file mode 100644
50dc83
index 0000000..a985f42
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/Makefile.am
50dc83
@@ -0,0 +1,3 @@
50dc83
+SUBDIRS = src
50dc83
+
50dc83
+CLEANFILES =
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/Makefile.am b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/Makefile.am
50dc83
new file mode 100644
50dc83
index 0000000..b512464
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/Makefile.am
50dc83
@@ -0,0 +1,12 @@
50dc83
+csp_LTLIBRARIES = cloudsynccvlt.la
50dc83
+cspdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/cloudsync-plugins
50dc83
+
50dc83
+cloudsynccvlt_la_SOURCES = libcvlt.c  $(top_srcdir)/xlators/features/cloudsync/src/cloudsync-common.c
50dc83
+cloudsynccvlt_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
50dc83
+cloudsynccvlt_la_LDFLAGS = -module -avoid-version -export-symbols $(top_srcdir)/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcloudsynccvlt.sym
50dc83
+AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src   -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src
50dc83
+noinst_HEADERS = archivestore.h libcvlt.h libcvlt-mem-types.h cvlt-messages.h
50dc83
+AM_CFLAGS = -Wall -fno-strict-aliasing $(GF_CFLAGS) -I$(top_srcdir)/xlators/features/cloudsync/src
50dc83
+CLEANFILES =
50dc83
+
50dc83
+EXTRA_DIST = libcloudsynccvlt.sym
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/archivestore.h b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/archivestore.h
50dc83
new file mode 100644
50dc83
index 0000000..7230ef7
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/archivestore.h
50dc83
@@ -0,0 +1,203 @@
50dc83
+/*
50dc83
+  Copyright (c) 2018 Commvault Systems, Inc. <http://www.commvault.com>
50dc83
+  This file is part of GlusterFS.
50dc83
+
50dc83
+  This file is licensed to you under your choice of the GNU Lesser
50dc83
+  General Public License, version 3 or any later version (LGPLv3 or
50dc83
+  later), or the GNU General Public License, version 2 (GPLv2), in all
50dc83
+  cases as published by the Free Software Foundation.
50dc83
+*/
50dc83
+
50dc83
+#ifndef __ARCHIVESTORE_H__
50dc83
+#define __ARCHIVESTORE_H__
50dc83
+
50dc83
+#include <stdlib.h>
50dc83
+#include <stddef.h>
50dc83
+#include <stdint.h>
50dc83
+#include <dlfcn.h>
50dc83
+#include <uuid/uuid.h>
50dc83
+
50dc83
+#define CS_XATTR_ARCHIVE_UUID "trusted.cloudsync.uuid"
50dc83
+#define CS_XATTR_PRODUCT_ID "trusted.cloudsync.product-id"
50dc83
+#define CS_XATTR_STORE_ID "trusted.cloudsync.store-id"
50dc83
+
50dc83
+struct _archstore_methods;
50dc83
+typedef struct _archstore_methods archstore_methods_t;
50dc83
+
50dc83
+struct _archstore_desc {
50dc83
+    void *priv; /* Private field for store mgmt.   */
50dc83
+                /* To be used only by archive store*/
50dc83
+};
50dc83
+typedef struct _archstore_desc archstore_desc_t;
50dc83
+
50dc83
+struct _archstore_info {
50dc83
+    char *id;         /* Identifier for the archivestore */
50dc83
+    uint32_t idlen;   /* Length of identifier string     */
50dc83
+    char *prod;       /* Name of the data mgmt. product  */
50dc83
+    uint32_t prodlen; /* Length of the product string    */
50dc83
+};
50dc83
+typedef struct _archstore_info archstore_info_t;
50dc83
+
50dc83
+struct _archstore_fileinfo {
50dc83
+    uuid_t uuid;         /* uuid of the file                */
50dc83
+    char *path;          /* file path                       */
50dc83
+    uint32_t pathlength; /* length of file path             */
50dc83
+};
50dc83
+typedef struct _archstore_fileinfo archstore_fileinfo_t;
50dc83
+
50dc83
+struct _app_callback_info {
50dc83
+    archstore_info_t *src_archstore;
50dc83
+    archstore_fileinfo_t *src_archfile;
50dc83
+    archstore_info_t *dest_archstore;
50dc83
+    archstore_fileinfo_t *dest_archfile;
50dc83
+};
50dc83
+typedef struct _app_callback_info app_callback_info_t;
50dc83
+
50dc83
+typedef void (*app_callback_t)(archstore_desc_t *, app_callback_info_t *,
50dc83
+                               void *, int64_t, int32_t);
50dc83
+
50dc83
+enum _archstore_scan_type { FULL = 1, INCREMENTAL = 2 };
50dc83
+typedef enum _archstore_scan_type archstore_scan_type_t;
50dc83
+
50dc83
+typedef int32_t archstore_errno_t;
50dc83
+
50dc83
+/*
50dc83
+ * Initialize archive store.
50dc83
+ * arg1  pointer to structure containing archive store information
50dc83
+ * arg2  error number if any generated during the initialization
50dc83
+ * arg3  name of the log file
50dc83
+ */
50dc83
+typedef int32_t (*init_archstore_t)(archstore_desc_t *, archstore_errno_t *,
50dc83
+                                    const char *);
50dc83
+
50dc83
+/*
50dc83
+ * Clean up archive store.
50dc83
+ * arg1  pointer to structure containing archive store information
50dc83
+ * arg2  error number if any generated during the cleanup
50dc83
+ */
50dc83
+typedef int32_t (*term_archstore_t)(archstore_desc_t *, archstore_errno_t *);
50dc83
+
50dc83
+/*
50dc83
+ * Read the contents of the file from archive store
50dc83
+ * arg1  pointer to structure containing archive store description
50dc83
+ * arg2  pointer to structure containing archive store information
50dc83
+ * arg3  pointer to structure containing information about file to be read
50dc83
+ * arg4  offset in the file from which data should be read
50dc83
+ * arg5  buffer where the data should be read
50dc83
+ * arg6  number of bytes of data to be read
50dc83
+ * arg7  error number if any generated during the read from file
50dc83
+ * arg8  callback handler to be invoked after the data is read
50dc83
+ * arg9  cookie to be passed when callback is invoked
50dc83
+ */
50dc83
+typedef int32_t (*read_archstore_t)(archstore_desc_t *, archstore_info_t *,
50dc83
+                                    archstore_fileinfo_t *, off_t, char *,
50dc83
+                                    size_t, archstore_errno_t *, app_callback_t,
50dc83
+                                    void *);
50dc83
+
50dc83
+/*
50dc83
+ * Restore the contents of the file from archive store
50dc83
+ * This is basically in-place restore
50dc83
+ * arg1  pointer to structure containing archive store description
50dc83
+ * arg2  pointer to structure containing archive store information
50dc83
+ * arg3  pointer to structure containing information about file to be restored
50dc83
+ * arg4  error number if any generated during the file restore
50dc83
+ * arg5  callback to be invoked after the file is restored
50dc83
+ * arg6  cookie to be passed when callback is invoked
50dc83
+ */
50dc83
+typedef int32_t (*recall_archstore_t)(archstore_desc_t *, archstore_info_t *,
50dc83
+                                      archstore_fileinfo_t *,
50dc83
+                                      archstore_errno_t *, app_callback_t,
50dc83
+                                      void *);
50dc83
+
50dc83
+/*
50dc83
+ * Restore the contents of the file from archive store to a different store
50dc83
+ * This is basically out-of-place restore
50dc83
+ * arg1  pointer to structure containing archive store description
50dc83
+ * arg2  pointer to structure containing source archive store information
50dc83
+ * arg3  pointer to structure containing information about file to be restored
50dc83
+ * arg4  pointer to structure containing destination archive store information
50dc83
+ * arg5  pointer to structure containing information about the location to
50dc83
+         which the file will be restored
50dc83
+ * arg6  error number if any generated during the file restore
50dc83
+ * arg7  callback to be invoked after the file is restored
50dc83
+ * arg8  cookie to be passed when callback is invoked
50dc83
+ */
50dc83
+typedef int32_t (*restore_archstore_t)(archstore_desc_t *, archstore_info_t *,
50dc83
+                                       archstore_fileinfo_t *,
50dc83
+                                       archstore_info_t *,
50dc83
+                                       archstore_fileinfo_t *,
50dc83
+                                       archstore_errno_t *, app_callback_t,
50dc83
+                                       void *);
50dc83
+
50dc83
+/*
50dc83
+ * Archive the contents of the file to archive store
50dc83
+ * arg1  pointer to structure containing archive store description
50dc83
+ * arg2  pointer to structure containing source archive store information
50dc83
+ * arg3  pointer to structure containing information about files to be archived
50dc83
+ * arg4  pointer to structure containing destination archive store information
50dc83
+ * arg5  pointer to structure containing information about files that failed
50dc83
+ *       to be archived
50dc83
+ * arg6  error number if any generated during the file archival
50dc83
+ * arg7  callback to be invoked after the file is archived
50dc83
+ * arg8  cookie to be passed when callback is invoked
50dc83
+ */
50dc83
+typedef int32_t (*archive_archstore_t)(archstore_desc_t *, archstore_info_t *,
50dc83
+                                       archstore_fileinfo_t *,
50dc83
+                                       archstore_info_t *,
50dc83
+                                       archstore_fileinfo_t *,
50dc83
+                                       archstore_errno_t *, app_callback_t,
50dc83
+                                       void *);
50dc83
+
50dc83
+/*
50dc83
+ * Backup list of files provided in the input file
50dc83
+ * arg1  pointer to structure containing archive store description
50dc83
+ * arg2  pointer to structure containing source archive store information
50dc83
+ * arg3  pointer to structure containing information about files to be backed up
50dc83
+ * arg4  pointer to structure containing destination archive store information
50dc83
+ * arg5  pointer to structure containing information about files that failed
50dc83
+ *       to be backed up
50dc83
+ * arg6  error number if any generated during the file archival
50dc83
+ * arg7  callback to be invoked after the file is archived
50dc83
+ * arg8  cookie to be passed when callback is invoked
50dc83
+ */
50dc83
+typedef int32_t (*backup_archstore_t)(archstore_desc_t *, archstore_info_t *,
50dc83
+                                      archstore_fileinfo_t *,
50dc83
+                                      archstore_info_t *,
50dc83
+                                      archstore_fileinfo_t *,
50dc83
+                                      archstore_errno_t *, app_callback_t,
50dc83
+                                      void *);
50dc83
+
50dc83
+/*
50dc83
+ * Scan the contents of a store and determine the files which need to be
50dc83
+ * backed up.
50dc83
+ * arg1  pointer to structure containing archive store description
50dc83
+ * arg2  pointer to structure containing archive store information
50dc83
+ * arg3  type of scan whether full or incremental
50dc83
+ * arg4  path to file that contains list of files to be backed up
50dc83
+ * arg5  error number if any generated during scan operation
50dc83
+ */
50dc83
+typedef int32_t (*scan_archstore_t)(archstore_desc_t *, archstore_info_t *,
50dc83
+                                    archstore_scan_type_t, char *,
50dc83
+                                    archstore_errno_t *);
50dc83
+
50dc83
+struct _archstore_methods {
50dc83
+    init_archstore_t init;
50dc83
+    term_archstore_t fini;
50dc83
+    backup_archstore_t backup;
50dc83
+    archive_archstore_t archive;
50dc83
+    scan_archstore_t scan;
50dc83
+    restore_archstore_t restore;
50dc83
+    recall_archstore_t recall;
50dc83
+    read_archstore_t read;
50dc83
+};
50dc83
+
50dc83
+typedef int (*get_archstore_methods_t)(archstore_methods_t *);
50dc83
+
50dc83
+/*
50dc83
+ * Single function that will be invoked by applications for extracting
50dc83
+ * the function pointers to all data management functions.
50dc83
+ */
50dc83
+int32_t
50dc83
+get_archstore_methods(archstore_methods_t *);
50dc83
+
50dc83
+#endif /* End of __ARCHIVESTORE_H__ */
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/cvlt-messages.h b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/cvlt-messages.h
50dc83
new file mode 100644
50dc83
index 0000000..57c9aa7
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/cvlt-messages.h
50dc83
@@ -0,0 +1,30 @@
50dc83
+/*
50dc83
+ Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com>
50dc83
+ This file is part of GlusterFS.
50dc83
+
50dc83
+ This file is licensed to you under your choice of the GNU Lesser
50dc83
+ General Public License, version 3 or any later version (LGPLv3 or
50dc83
+ later), or the GNU General Public License, version 2 (GPLv2), in all
50dc83
+ cases as published by the Free Software Foundation.
50dc83
+ */
50dc83
+
50dc83
+#ifndef _CVLT_MESSAGES_H_
50dc83
+#define _CVLT_MESSAGES_H_
50dc83
+
50dc83
+#include <glusterfs/glfs-message-id.h>
50dc83
+
50dc83
+/* To add new message IDs, append new identifiers at the end of the list.
50dc83
+ *
50dc83
+ * Never remove a message ID. If it's not used anymore, you can rename it or
50dc83
+ * leave it as it is, but not delete it. This is to prevent reutilization of
50dc83
+ * IDs by other messages.
50dc83
+ *
50dc83
+ * The component name must match one of the entries defined in
50dc83
+ * glfs-message-id.h.
50dc83
+ */
50dc83
+
50dc83
+GLFS_MSGID(CVLT, CVLT_EXTRACTION_FAILED, CVLT_FREE,
50dc83
+           CVLT_RESOURCE_ALLOCATION_FAILED, CVLT_RESTORE_FAILED,
50dc83
+           CVLT_READ_FAILED, CVLT_NO_MEMORY, CVLT_DLOPEN_FAILED);
50dc83
+
50dc83
+#endif /* !_CVLT_MESSAGES_H_ */
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcloudsynccvlt.sym b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcloudsynccvlt.sym
50dc83
new file mode 100644
50dc83
index 0000000..0bc2736
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcloudsynccvlt.sym
50dc83
@@ -0,0 +1 @@
50dc83
+store_ops
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt-mem-types.h b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt-mem-types.h
50dc83
new file mode 100644
50dc83
index 0000000..c24fab8
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt-mem-types.h
50dc83
@@ -0,0 +1,19 @@
50dc83
+/*
50dc83
+ *   Copyright (c) 2018 Commvault Systems, Inc. <http://www.commvault.com>
50dc83
+ *   This file is part of GlusterFS.
50dc83
+ *
50dc83
+ *   This file is licensed to you under your choice of the GNU Lesser
50dc83
+ *   General Public License, version 3 or any later version (LGPLv3 or
50dc83
+ *   later), or the GNU General Public License, version 2 (GPLv2), in all
50dc83
+ *   cases as published by the Free Software Foundation.
50dc83
+ */
50dc83
+
50dc83
+#ifndef __LIBCVLT_MEM_TYPES_H__
50dc83
+#define __LIBCVLT_MEM_TYPES_H__
50dc83
+
50dc83
+#include <glusterfs/mem-types.h>
50dc83
+enum libcvlt_mem_types_ {
50dc83
+    gf_libcvlt_mt_cvlt_private_t = gf_common_mt_end + 1,
50dc83
+    gf_libcvlt_mt_end
50dc83
+};
50dc83
+#endif /* __LIBCVLT_MEM_TYPES_H__ */
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.c b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.c
50dc83
new file mode 100644
50dc83
index 0000000..e827882
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.c
50dc83
@@ -0,0 +1,842 @@
50dc83
+#include <stdlib.h>
50dc83
+#include <glusterfs/xlator.h>
50dc83
+#include <glusterfs/glusterfs.h>
50dc83
+#include "libcvlt.h"
50dc83
+#include "cloudsync-common.h"
50dc83
+#include "cvlt-messages.h"
50dc83
+
50dc83
+#define LIBARCHIVE_SO "libopenarchive.so"
50dc83
+#define ALIGN_SIZE 4096
50dc83
+#define CVLT_TRAILER "cvltv1"
50dc83
+
50dc83
+store_methods_t store_ops = {
50dc83
+    .fop_download = cvlt_download,
50dc83
+    .fop_init = cvlt_init,
50dc83
+    .fop_reconfigure = cvlt_reconfigure,
50dc83
+    .fop_fini = cvlt_fini,
50dc83
+    .fop_remote_read = cvlt_read,
50dc83
+};
50dc83
+
50dc83
+static const int32_t num_req = 32;
50dc83
+static const int32_t num_iatt = 32;
50dc83
+static char *plugin = "cvlt_cloudSync";
50dc83
+
50dc83
+int32_t
50dc83
+mem_acct_init(xlator_t *this)
50dc83
+{
50dc83
+    int ret = -1;
50dc83
+
50dc83
+    if (!this)
50dc83
+        return ret;
50dc83
+
50dc83
+    ret = xlator_mem_acct_init(this, gf_libcvlt_mt_end + 1);
50dc83
+
50dc83
+    if (ret != 0) {
50dc83
+        return ret;
50dc83
+    }
50dc83
+
50dc83
+    return ret;
50dc83
+}
50dc83
+
50dc83
+static void
50dc83
+cvlt_free_resources(archive_t *arch)
50dc83
+{
50dc83
+    /*
50dc83
+     * We will release all the resources that were allocated by the xlator.
50dc83
+     * Check whether there are any buffers which have not been released
50dc83
+     * back to a mempool.
50dc83
+     */
50dc83
+
50dc83
+    if (arch->handle) {
50dc83
+        dlclose(arch->handle);
50dc83
+    }
50dc83
+
50dc83
+    if (arch->iobuf_pool) {
50dc83
+        iobuf_pool_destroy(arch->iobuf_pool);
50dc83
+    }
50dc83
+
50dc83
+    if (arch->req_pool) {
50dc83
+        mem_pool_destroy(arch->req_pool);
50dc83
+        arch->req_pool = NULL;
50dc83
+    }
50dc83
+
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_extract_store_fops(xlator_t *this, archive_t *arch)
50dc83
+{
50dc83
+    int32_t op_ret = -1;
50dc83
+    get_archstore_methods_t get_archstore_methods;
50dc83
+
50dc83
+    /*
50dc83
+     * libopenarchive.so defines methods for performing data management
50dc83
+     * operations. We will extract the methods from library and these
50dc83
+     * methods will be invoked for moving data between glusterfs volume
50dc83
+     * and the data management product.
50dc83
+     */
50dc83
+
50dc83
+    VALIDATE_OR_GOTO(arch, err);
50dc83
+
50dc83
+    arch->handle = dlopen(LIBARCHIVE_SO, RTLD_NOW);
50dc83
+    if (!arch->handle) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_DLOPEN_FAILED,
50dc83
+               " failed to open %s ", LIBARCHIVE_SO);
50dc83
+        return op_ret;
50dc83
+    }
50dc83
+
50dc83
+    dlerror(); /* Clear any existing error */
50dc83
+
50dc83
+    get_archstore_methods = dlsym(arch->handle, "get_archstore_methods");
50dc83
+    if (!get_archstore_methods) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " Error extracting get_archstore_methods()");
50dc83
+        dlclose(arch->handle);
50dc83
+        arch->handle = NULL;
50dc83
+        return op_ret;
50dc83
+    }
50dc83
+
50dc83
+    op_ret = get_archstore_methods(&(arch->fops));
50dc83
+    if (op_ret) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " Failed to extract methods in get_archstore_methods");
50dc83
+        dlclose(arch->handle);
50dc83
+        arch->handle = NULL;
50dc83
+        return op_ret;
50dc83
+    }
50dc83
+
50dc83
+err:
50dc83
+    return op_ret;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_alloc_resources(xlator_t *this, archive_t *arch, int num_req, int num_iatt)
50dc83
+{
50dc83
+    /*
50dc83
+     * Initialize information about all the memory pools that will be
50dc83
+     * used by this xlator.
50dc83
+     */
50dc83
+    arch->nreqs = 0;
50dc83
+
50dc83
+    arch->req_pool = NULL;
50dc83
+
50dc83
+    arch->handle = NULL;
50dc83
+    arch->xl = this;
50dc83
+
50dc83
+    arch->req_pool = mem_pool_new(cvlt_request_t, num_req);
50dc83
+    if (!arch->req_pool) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    arch->iobuf_pool = iobuf_pool_new();
50dc83
+    if (!arch->iobuf_pool) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    if (cvlt_extract_store_fops(this, arch)) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    return 0;
50dc83
+
50dc83
+err:
50dc83
+
50dc83
+    return -1;
50dc83
+}
50dc83
+
50dc83
+static void
50dc83
+cvlt_req_init(cvlt_request_t *req)
50dc83
+{
50dc83
+    sem_init(&(req->sem), 0, 0);
50dc83
+
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
+static void
50dc83
+cvlt_req_destroy(cvlt_request_t *req)
50dc83
+{
50dc83
+    if (req->iobuf) {
50dc83
+        iobuf_unref(req->iobuf);
50dc83
+    }
50dc83
+
50dc83
+    if (req->iobref) {
50dc83
+        iobref_unref(req->iobref);
50dc83
+    }
50dc83
+
50dc83
+    sem_destroy(&(req->sem));
50dc83
+
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
+static cvlt_request_t *
50dc83
+cvlt_alloc_req(archive_t *arch)
50dc83
+{
50dc83
+    cvlt_request_t *reqptr = NULL;
50dc83
+
50dc83
+    if (!arch) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    if (arch->req_pool) {
50dc83
+        reqptr = mem_get0(arch->req_pool);
50dc83
+        if (reqptr) {
50dc83
+            cvlt_req_init(reqptr);
50dc83
+        }
50dc83
+    }
50dc83
+
50dc83
+    if (reqptr) {
50dc83
+        LOCK(&(arch->lock));
50dc83
+        arch->nreqs++;
50dc83
+        UNLOCK(&(arch->lock));
50dc83
+    }
50dc83
+
50dc83
+err:
50dc83
+    return reqptr;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_free_req(archive_t *arch, cvlt_request_t *reqptr)
50dc83
+{
50dc83
+    if (!reqptr) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    if (!arch) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    if (arch->req_pool) {
50dc83
+        /*
50dc83
+         * Free the request resources if they exist.
50dc83
+         */
50dc83
+
50dc83
+        cvlt_req_destroy(reqptr);
50dc83
+        mem_put(reqptr);
50dc83
+
50dc83
+        LOCK(&(arch->lock));
50dc83
+        arch->nreqs--;
50dc83
+        UNLOCK(&(arch->lock));
50dc83
+    }
50dc83
+
50dc83
+    return 0;
50dc83
+
50dc83
+err:
50dc83
+    return -1;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_init_xlator(xlator_t *this, archive_t *arch, int num_req, int num_iatt)
50dc83
+{
50dc83
+    int32_t ret = -1;
50dc83
+    int32_t errnum = -1;
50dc83
+    int32_t locked = 0;
50dc83
+
50dc83
+    /*
50dc83
+     * Perform all the initializations needed for brining up the xlator.
50dc83
+     */
50dc83
+    if (!arch) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    LOCK_INIT(&(arch->lock));
50dc83
+    LOCK(&(arch->lock));
50dc83
+
50dc83
+    locked = 1;
50dc83
+
50dc83
+    ret = cvlt_alloc_resources(this, arch, num_req, num_iatt);
50dc83
+
50dc83
+    if (ret) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * Now that the fops have been extracted initialize the store
50dc83
+     */
50dc83
+    ret = arch->fops.init(&(arch->descinfo), &errnum, plugin);
50dc83
+    if (ret) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    UNLOCK(&(arch->lock));
50dc83
+    locked = 0;
50dc83
+    ret = 0;
50dc83
+
50dc83
+    return ret;
50dc83
+
50dc83
+err:
50dc83
+    cvlt_free_resources(arch);
50dc83
+
50dc83
+    if (locked) {
50dc83
+        UNLOCK(&(arch->lock));
50dc83
+    }
50dc83
+
50dc83
+    return ret;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_term_xlator(archive_t *arch)
50dc83
+{
50dc83
+    int32_t errnum = -1;
50dc83
+
50dc83
+    if (!arch) {
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    LOCK(&(arch->lock));
50dc83
+
50dc83
+    /*
50dc83
+     * Release the resources that have been allocated inside store
50dc83
+     */
50dc83
+    arch->fops.fini(&(arch->descinfo), &errnum);
50dc83
+
50dc83
+    cvlt_free_resources(arch);
50dc83
+
50dc83
+    UNLOCK(&(arch->lock));
50dc83
+
50dc83
+    GF_FREE(arch);
50dc83
+
50dc83
+    return 0;
50dc83
+
50dc83
+err:
50dc83
+    return -1;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_init_store_info(archive_t *priv, archstore_info_t *store_info)
50dc83
+{
50dc83
+    if (!store_info) {
50dc83
+        return -1;
50dc83
+    }
50dc83
+
50dc83
+    store_info->prod = priv->product_id;
50dc83
+    store_info->prodlen = strlen(priv->product_id);
50dc83
+
50dc83
+    store_info->id = priv->store_id;
50dc83
+    store_info->idlen = strlen(priv->store_id);
50dc83
+
50dc83
+    return 0;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_init_file_info(cs_loc_xattr_t *xattr, archstore_fileinfo_t *file_info)
50dc83
+{
50dc83
+    if (!xattr || !file_info) {
50dc83
+        return -1;
50dc83
+    }
50dc83
+
50dc83
+    gf_uuid_copy(file_info->uuid, xattr->uuid);
50dc83
+    file_info->path = xattr->file_path;
50dc83
+    file_info->pathlength = strlen(xattr->file_path);
50dc83
+
50dc83
+    return 0;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_init_gluster_store_info(cs_loc_xattr_t *xattr,
50dc83
+                             archstore_info_t *store_info)
50dc83
+{
50dc83
+    static char *product = "glusterfs";
50dc83
+
50dc83
+    if (!xattr || !store_info) {
50dc83
+        return -1;
50dc83
+    }
50dc83
+
50dc83
+    store_info->prod = product;
50dc83
+    store_info->prodlen = strlen(product);
50dc83
+
50dc83
+    store_info->id = xattr->volname;
50dc83
+    store_info->idlen = strlen(xattr->volname);
50dc83
+
50dc83
+    return 0;
50dc83
+}
50dc83
+
50dc83
+static int32_t
50dc83
+cvlt_init_gluster_file_info(cs_loc_xattr_t *xattr,
50dc83
+                            archstore_fileinfo_t *file_info)
50dc83
+{
50dc83
+    if (!xattr || !file_info) {
50dc83
+        return -1;
50dc83
+    }
50dc83
+
50dc83
+    gf_uuid_copy(file_info->uuid, xattr->gfid);
50dc83
+    file_info->path = xattr->file_path;
50dc83
+    file_info->pathlength = strlen(xattr->file_path);
50dc83
+
50dc83
+    return 0;
50dc83
+}
50dc83
+
50dc83
+static void
50dc83
+cvlt_copy_stat_info(struct iatt *buf, cs_size_xattr_t *xattrs)
50dc83
+{
50dc83
+    /*
50dc83
+     * If the file was archived then the reported size will not be a
50dc83
+     * correct one. We need to fix this.
50dc83
+     */
50dc83
+    if (buf && xattrs) {
50dc83
+        buf->ia_size = xattrs->size;
50dc83
+        buf->ia_blksize = xattrs->blksize;
50dc83
+        buf->ia_blocks = xattrs->blocks;
50dc83
+    }
50dc83
+
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
+static void
50dc83
+cvlt_readv_complete(archstore_desc_t *desc, app_callback_info_t *cbkinfo,
50dc83
+                    void *cookie, int64_t op_ret, int32_t op_errno)
50dc83
+{
50dc83
+    struct iovec iov;
50dc83
+    xlator_t *this = NULL;
50dc83
+    struct iatt postbuf = {
50dc83
+        0,
50dc83
+    };
50dc83
+    call_frame_t *frame = NULL;
50dc83
+    cvlt_request_t *req = (cvlt_request_t *)cookie;
50dc83
+    cs_local_t *local = NULL;
50dc83
+    cs_private_t *cspriv = NULL;
50dc83
+    archive_t *priv = NULL;
50dc83
+
50dc83
+    frame = req->frame;
50dc83
+    this = frame->this;
50dc83
+    local = frame->local;
50dc83
+
50dc83
+    cspriv = this->private;
50dc83
+    priv = (archive_t *)cspriv->stores->config;
50dc83
+
50dc83
+    if (strcmp(priv->trailer, CVLT_TRAILER)) {
50dc83
+        op_ret = -1;
50dc83
+        op_errno = EINVAL;
50dc83
+        goto out;
50dc83
+    }
50dc83
+
50dc83
+    gf_msg_debug(plugin, 0,
50dc83
+                 " Read callback invoked offset:%" PRIu64 "bytes: %" PRIu64
50dc83
+                 " op : %d ret : %" PRId64 " errno : %d",
50dc83
+                 req->offset, req->bytes, req->op_type, op_ret, op_errno);
50dc83
+
50dc83
+    if (op_ret < 0) {
50dc83
+        goto out;
50dc83
+    }
50dc83
+
50dc83
+    req->iobref = iobref_new();
50dc83
+    if (!req->iobref) {
50dc83
+        op_ret = -1;
50dc83
+        op_errno = ENOMEM;
50dc83
+        goto out;
50dc83
+    }
50dc83
+
50dc83
+    iobref_add(req->iobref, req->iobuf);
50dc83
+    iov.iov_base = iobuf_ptr(req->iobuf);
50dc83
+    iov.iov_len = op_ret;
50dc83
+
50dc83
+    cvlt_copy_stat_info(&postbuf, &(req->szxattr));
50dc83
+
50dc83
+    /*
50dc83
+     * Hack to notify higher layers of EOF.
50dc83
+     */
50dc83
+    if (!postbuf.ia_size || (req->offset + iov.iov_len >= postbuf.ia_size)) {
50dc83
+        gf_msg_debug(plugin, 0, " signalling end-of-file for uuid=%s",
50dc83
+                     uuid_utoa(req->file_info.uuid));
50dc83
+        op_errno = ENOENT;
50dc83
+    }
50dc83
+
50dc83
+out:
50dc83
+
50dc83
+    STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, &iov, 1, &postbuf,
50dc83
+                        req->iobref, local->xattr_rsp);
50dc83
+
50dc83
+    if (req) {
50dc83
+        cvlt_free_req(priv, req);
50dc83
+    }
50dc83
+
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
+static void
50dc83
+cvlt_download_complete(archstore_desc_t *store, app_callback_info_t *cbk_info,
50dc83
+                       void *cookie, int64_t ret, int errcode)
50dc83
+{
50dc83
+    cvlt_request_t *req = (cvlt_request_t *)cookie;
50dc83
+
50dc83
+    gf_msg_debug(plugin, 0,
50dc83
+                 " Download callback invoked  ret : %" PRId64 " errno : %d",
50dc83
+                 ret, errcode);
50dc83
+
50dc83
+    req->op_ret = ret;
50dc83
+    req->op_errno = errcode;
50dc83
+    sem_post(&(req->sem));
50dc83
+
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
+void *
50dc83
+cvlt_init(xlator_t *this)
50dc83
+{
50dc83
+    int ret = 0;
50dc83
+    archive_t *priv = NULL;
50dc83
+
50dc83
+    if (!this->children || this->children->next) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, ENOMEM, 0,
50dc83
+               "should have exactly one child");
50dc83
+        ret = -1;
50dc83
+        goto out;
50dc83
+    }
50dc83
+
50dc83
+    if (!this->parents) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, ENOMEM, 0,
50dc83
+               "dangling volume. check volfile");
50dc83
+        ret = -1;
50dc83
+        goto out;
50dc83
+    }
50dc83
+
50dc83
+    priv = GF_CALLOC(1, sizeof(archive_t), gf_libcvlt_mt_cvlt_private_t);
50dc83
+    if (!priv) {
50dc83
+        ret = -1;
50dc83
+        goto out;
50dc83
+    }
50dc83
+
50dc83
+    priv->trailer = CVLT_TRAILER;
50dc83
+    if (cvlt_init_xlator(this, priv, num_req, num_iatt)) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, ENOMEM, 0, "xlator init failed");
50dc83
+        ret = -1;
50dc83
+        goto out;
50dc83
+    }
50dc83
+
50dc83
+    GF_OPTION_INIT("cloudsync-store-id", priv->store_id, str, out);
50dc83
+    GF_OPTION_INIT("cloudsync-product-id", priv->product_id, str, out);
50dc83
+
50dc83
+    gf_msg(plugin, GF_LOG_INFO, 0, 0,
50dc83
+           "store id is : %s "
50dc83
+           "product id is : %s.",
50dc83
+           priv->store_id, priv->product_id);
50dc83
+out:
50dc83
+    if (ret == -1) {
50dc83
+        cvlt_term_xlator(priv);
50dc83
+        return (NULL);
50dc83
+    }
50dc83
+    return priv;
50dc83
+}
50dc83
+
50dc83
+int
50dc83
+cvlt_reconfigure(xlator_t *this, dict_t *options)
50dc83
+{
50dc83
+    cs_private_t *cspriv = NULL;
50dc83
+    archive_t *priv = NULL;
50dc83
+
50dc83
+    cspriv = this->private;
50dc83
+    priv = (archive_t *)cspriv->stores->config;
50dc83
+
50dc83
+    if (strcmp(priv->trailer, CVLT_TRAILER))
50dc83
+        goto out;
50dc83
+
50dc83
+    GF_OPTION_RECONF("cloudsync-store-id", priv->store_id, options, str, out);
50dc83
+
50dc83
+    GF_OPTION_RECONF("cloudsync-product-id", priv->product_id, options, str,
50dc83
+                     out);
50dc83
+    gf_msg_debug(plugin, 0,
50dc83
+                 "store id is : %s "
50dc83
+                 "product id is : %s.",
50dc83
+                 priv->store_id, priv->product_id);
50dc83
+    return 0;
50dc83
+out:
50dc83
+    return -1;
50dc83
+}
50dc83
+
50dc83
+void
50dc83
+cvlt_fini(void *config)
50dc83
+{
50dc83
+    archive_t *priv = NULL;
50dc83
+
50dc83
+    priv = (archive_t *)config;
50dc83
+
50dc83
+    if (strcmp(priv->trailer, CVLT_TRAILER))
50dc83
+        return;
50dc83
+
50dc83
+    cvlt_term_xlator(priv);
50dc83
+    gf_msg(plugin, GF_LOG_INFO, 0, CVLT_FREE, " released xlator resources");
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
+int
50dc83
+cvlt_download(call_frame_t *frame, void *config)
50dc83
+{
50dc83
+    archive_t *parch = NULL;
50dc83
+    cs_local_t *local = frame->local;
50dc83
+    cs_loc_xattr_t *locxattr = local->xattrinfo.lxattr;
50dc83
+    cvlt_request_t *req = NULL;
50dc83
+    archstore_info_t dest_storeinfo;
50dc83
+    archstore_fileinfo_t dest_fileinfo;
50dc83
+    int32_t op_ret, op_errno;
50dc83
+
50dc83
+    parch = (archive_t *)config;
50dc83
+
50dc83
+    if (strcmp(parch->trailer, CVLT_TRAILER)) {
50dc83
+        op_ret = -1;
50dc83
+        op_errno = EINVAL;
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    gf_msg_debug(plugin, 0, " download invoked for uuid = %s  gfid=%s ",
50dc83
+                 locxattr->uuid, uuid_utoa(locxattr->gfid));
50dc83
+
50dc83
+    if (!(parch->fops.restore)) {
50dc83
+        op_errno = ELIBBAD;
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * Download needs to be processed. Allocate a request.
50dc83
+     */
50dc83
+    req = cvlt_alloc_req(parch);
50dc83
+
50dc83
+    if (!req) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, ENOMEM, CVLT_RESOURCE_ALLOCATION_FAILED,
50dc83
+               " failed to allocated request for gfid=%s",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        op_errno = ENOMEM;
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * Initialize the request object.
50dc83
+     */
50dc83
+    req->op_type = CVLT_RESTORE_OP;
50dc83
+    req->frame = frame;
50dc83
+
50dc83
+    /*
50dc83
+     * The file is currently residing inside a data management store.
50dc83
+     * To restore the file contents we need to provide the information
50dc83
+     * about data management store.
50dc83
+     */
50dc83
+    op_ret = cvlt_init_store_info(parch, &(req->store_info));
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " failed to extract store info for gfid=%s",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    op_ret = cvlt_init_file_info(locxattr, &(req->file_info));
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " failed to extract file info for gfid=%s",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * We need t perform in-place restore of the file from data managment
50dc83
+     * store to gusterfs volume.
50dc83
+     */
50dc83
+    op_ret = cvlt_init_gluster_store_info(locxattr, &dest_storeinfo);
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " failed to extract destination store info for gfid=%s",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    op_ret = cvlt_init_gluster_file_info(locxattr, &dest_fileinfo);
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " failed to extract file info for gfid=%s",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * Submit the restore request.
50dc83
+     */
50dc83
+    op_ret = parch->fops.restore(&(parch->descinfo), &(req->store_info),
50dc83
+                                 &(req->file_info), &dest_storeinfo,
50dc83
+                                 &dest_fileinfo, &op_errno,
50dc83
+                                 cvlt_download_complete, req);
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_RESTORE_FAILED,
50dc83
+               " failed to restore file gfid=%s from data managment store",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * Wait for the restore to complete.
50dc83
+     */
50dc83
+    sem_wait(&(req->sem));
50dc83
+
50dc83
+    if (req->op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_RESTORE_FAILED,
50dc83
+               " restored failed for gfid=%s", uuid_utoa(locxattr->gfid));
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    if (req) {
50dc83
+        cvlt_free_req(parch, req);
50dc83
+    }
50dc83
+
50dc83
+    return 0;
50dc83
+
50dc83
+err:
50dc83
+
50dc83
+    if (req) {
50dc83
+        cvlt_free_req(parch, req);
50dc83
+    }
50dc83
+
50dc83
+    return -1;
50dc83
+}
50dc83
+
50dc83
+int
50dc83
+cvlt_read(call_frame_t *frame, void *config)
50dc83
+{
50dc83
+    int32_t op_ret = -1;
50dc83
+    int32_t op_errno = 0;
50dc83
+    archive_t *parch = NULL;
50dc83
+    cvlt_request_t *req = NULL;
50dc83
+    struct iovec iov = {
50dc83
+        0,
50dc83
+    };
50dc83
+    struct iobref *iobref;
50dc83
+    size_t size = 0;
50dc83
+    off_t off = 0;
50dc83
+
50dc83
+    cs_local_t *local = frame->local;
50dc83
+    cs_loc_xattr_t *locxattr = local->xattrinfo.lxattr;
50dc83
+
50dc83
+    size = local->xattrinfo.size;
50dc83
+    off = local->xattrinfo.offset;
50dc83
+
50dc83
+    parch = (archive_t *)config;
50dc83
+
50dc83
+    if (strcmp(parch->trailer, CVLT_TRAILER)) {
50dc83
+        op_ret = -1;
50dc83
+        op_errno = EINVAL;
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    gf_msg_debug(plugin, 0,
50dc83
+                 " read invoked for gfid = %s offset = %" PRIu64
50dc83
+                 " file_size = %" PRIu64,
50dc83
+                 uuid_utoa(locxattr->gfid), off, local->stbuf.ia_size);
50dc83
+
50dc83
+    if (off >= local->stbuf.ia_size) {
50dc83
+        /*
50dc83
+         * Hack to notify higher layers of EOF.
50dc83
+         */
50dc83
+
50dc83
+        op_errno = ENOENT;
50dc83
+        op_ret = 0;
50dc83
+
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_READ_FAILED,
50dc83
+               " reporting end-of-file for gfid=%s", uuid_utoa(locxattr->gfid));
50dc83
+
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    if (!size) {
50dc83
+        op_errno = EINVAL;
50dc83
+
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_READ_FAILED,
50dc83
+               " zero size read attempted on gfid=%s",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    if (!(parch->fops.read)) {
50dc83
+        op_errno = ELIBBAD;
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * The read request need to be processed. Allocate a request.
50dc83
+     */
50dc83
+    req = cvlt_alloc_req(parch);
50dc83
+
50dc83
+    if (!req) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, ENOMEM, CVLT_NO_MEMORY,
50dc83
+               " failed to allocated request for gfid=%s",
50dc83
+               uuid_utoa(locxattr->gfid));
50dc83
+        op_errno = ENOMEM;
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    req->iobuf = iobuf_get_page_aligned(parch->iobuf_pool, size, ALIGN_SIZE);
50dc83
+    if (!req->iobuf) {
50dc83
+        op_errno = ENOMEM;
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * Initialize the request object.
50dc83
+     */
50dc83
+    req->op_type = CVLT_READ_OP;
50dc83
+    req->offset = off;
50dc83
+    req->bytes = size;
50dc83
+    req->frame = frame;
50dc83
+    req->szxattr.size = local->stbuf.ia_size;
50dc83
+    req->szxattr.blocks = local->stbuf.ia_blocks;
50dc83
+    req->szxattr.blksize = local->stbuf.ia_blksize;
50dc83
+
50dc83
+    /*
50dc83
+     * The file is currently residing inside a data management store.
50dc83
+     * To read the file contents we need to provide the information
50dc83
+     * about data management store.
50dc83
+     */
50dc83
+    op_ret = cvlt_init_store_info(parch, &(req->store_info));
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " failed to extract store info for gfid=%s"
50dc83
+               " offset=%" PRIu64 " size=%" GF_PRI_SIZET
50dc83
+               ", "
50dc83
+               " buf=%p",
50dc83
+               uuid_utoa(locxattr->gfid), off, size, req->iobuf->ptr);
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    op_ret = cvlt_init_file_info(locxattr, &(req->file_info));
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " failed to extract file info for gfid=%s"
50dc83
+               " offset=%" PRIu64 " size=%" GF_PRI_SIZET
50dc83
+               ", "
50dc83
+               " buf=%p",
50dc83
+               uuid_utoa(locxattr->gfid), off, size, req->iobuf->ptr);
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    /*
50dc83
+     * Submit the read request.
50dc83
+     */
50dc83
+    op_ret = parch->fops.read(&(parch->descinfo), &(req->store_info),
50dc83
+                              &(req->file_info), off, req->iobuf->ptr, size,
50dc83
+                              &op_errno, cvlt_readv_complete, req);
50dc83
+
50dc83
+    if (op_ret < 0) {
50dc83
+        gf_msg(plugin, GF_LOG_ERROR, 0, CVLT_EXTRACTION_FAILED,
50dc83
+               " read failed on gfid=%s"
50dc83
+               " offset=%" PRIu64 " size=%" GF_PRI_SIZET
50dc83
+               ", "
50dc83
+               " buf=%p",
50dc83
+               uuid_utoa(locxattr->gfid), off, size, req->iobuf->ptr);
50dc83
+        goto err;
50dc83
+    }
50dc83
+
50dc83
+    return 0;
50dc83
+
50dc83
+err:
50dc83
+
50dc83
+    iobref = iobref_new();
50dc83
+    gf_msg_debug(plugin, 0, " read unwinding stack op_ret = %d, op_errno = %d",
50dc83
+                 op_ret, op_errno);
50dc83
+
50dc83
+    STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, &iov, 1,
50dc83
+                        &(local->stbuf), iobref, local->xattr_rsp);
50dc83
+
50dc83
+    if (iobref) {
50dc83
+        iobref_unref(iobref);
50dc83
+    }
50dc83
+
50dc83
+    if (req) {
50dc83
+        cvlt_free_req(parch, req);
50dc83
+    }
50dc83
+
50dc83
+    return 0;
50dc83
+}
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.h b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.h
50dc83
new file mode 100644
50dc83
index 0000000..c45ac94
50dc83
--- /dev/null
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cvlt/src/libcvlt.h
50dc83
@@ -0,0 +1,84 @@
50dc83
+/*
50dc83
+  Copyright (c) 2018 Commvault Systems, Inc. <http://www.commvault.com>
50dc83
+  This file is part of GlusterFS.
50dc83
+
50dc83
+  This file is licensed to you under your choice of the GNU Lesser
50dc83
+  General Public License, version 3 or any later version (LGPLv3 or
50dc83
+  later), or the GNU General Public License, version 2 (GPLv2), in all
50dc83
+  cases as published by the Free Software Foundation.
50dc83
+*/
50dc83
+#ifndef _LIBCVLT_H
50dc83
+#define _LIBCVLT_H
50dc83
+
50dc83
+#include <semaphore.h>
50dc83
+#include <glusterfs/xlator.h>
50dc83
+#include <glusterfs/glusterfs.h>
50dc83
+#include <glusterfs/call-stub.h>
50dc83
+#include <glusterfs/syncop.h>
50dc83
+#include <glusterfs/compat-errno.h>
50dc83
+#include "cloudsync-common.h"
50dc83
+#include "libcvlt-mem-types.h"
50dc83
+#include "archivestore.h"
50dc83
+
50dc83
+enum _cvlt_op {
50dc83
+    CVLT_READ_OP = 1,
50dc83
+    CVLT_WRITE_OP = 2,
50dc83
+    CVLT_RESTORE_OP = 3,
50dc83
+    CVLT_ARCHIVE_OP = 4,
50dc83
+    CVLT_LOOKUP_OP = 5,
50dc83
+    CVLT_XATTR_OP = 6,
50dc83
+    CVLT_STAT_OP = 7,
50dc83
+    CVLT_FSTAT_op = 8,
50dc83
+    CVLT_UNDEF_OP = 127
50dc83
+};
50dc83
+typedef enum _cvlt_op cvlt_op_t;
50dc83
+
50dc83
+struct _archive;
50dc83
+struct _cvlt_request {
50dc83
+    uint64_t offset;
50dc83
+    uint64_t bytes;
50dc83
+    struct iobuf *iobuf;
50dc83
+    struct iobref *iobref;
50dc83
+    call_frame_t *frame;
50dc83
+    cvlt_op_t op_type;
50dc83
+    int32_t op_ret;
50dc83
+    int32_t op_errno;
50dc83
+    xlator_t *this;
50dc83
+    sem_t sem;
50dc83
+    archstore_info_t store_info;
50dc83
+    archstore_fileinfo_t file_info;
50dc83
+    cs_size_xattr_t szxattr;
50dc83
+};
50dc83
+typedef struct _cvlt_request cvlt_request_t;
50dc83
+
50dc83
+struct _archive {
50dc83
+    gf_lock_t lock;                /* lock for controlling access   */
50dc83
+    xlator_t *xl;                  /* xlator                        */
50dc83
+    void *handle;                  /* handle returned from dlopen   */
50dc83
+    int32_t nreqs;                 /* num requests active           */
50dc83
+    struct mem_pool *req_pool;     /* pool for requests             */
50dc83
+    struct iobuf_pool *iobuf_pool; /* iobuff pool                   */
50dc83
+    archstore_desc_t descinfo;     /* Archive store descriptor info */
50dc83
+    archstore_methods_t fops;      /* function pointers             */
50dc83
+    char *product_id;
50dc83
+    char *store_id;
50dc83
+    char *trailer;
50dc83
+};
50dc83
+typedef struct _archive archive_t;
50dc83
+
50dc83
+void *
50dc83
+cvlt_init(xlator_t *);
50dc83
+
50dc83
+int
50dc83
+cvlt_reconfigure(xlator_t *, dict_t *);
50dc83
+
50dc83
+void
50dc83
+cvlt_fini(void *);
50dc83
+
50dc83
+int
50dc83
+cvlt_download(call_frame_t *, void *);
50dc83
+
50dc83
+int
50dc83
+cvlt_read(call_frame_t *, void *);
50dc83
+
50dc83
+#endif
50dc83
diff --git a/xlators/features/cloudsync/src/cloudsync.c b/xlators/features/cloudsync/src/cloudsync.c
50dc83
index 2240fc3..8026b05 100644
50dc83
--- a/xlators/features/cloudsync/src/cloudsync.c
50dc83
+++ b/xlators/features/cloudsync/src/cloudsync.c
50dc83
@@ -39,7 +39,11 @@ struct cs_plugin plugins[] = {
50dc83
     {.name = "cloudsyncs3",
50dc83
      .library = "cloudsyncs3.so",
50dc83
      .description = "cloudsync s3 store."},
50dc83
-
50dc83
+#if defined(__linux__)
50dc83
+    {.name = "cvlt",
50dc83
+     .library = "cloudsynccvlt.so",
50dc83
+     .description = "Commvault content store."},
50dc83
+#endif
50dc83
     {.name = NULL},
50dc83
 };
50dc83
 
50dc83
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
50dc83
index 73abf37..7a83124 100644
50dc83
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
50dc83
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
50dc83
@@ -3724,6 +3724,14 @@ struct volopt_map_entry glusterd_volopt_map[] = {
50dc83
     {.key = "features.cloudsync-remote-read",
50dc83
      .voltype = "features/cloudsync",
50dc83
      .value = "off",
50dc83
-     .op_version = GD_OP_VERSION_6_0,
50dc83
+     .op_version = GD_OP_VERSION_7_0,
50dc83
+     .flags = VOLOPT_FLAG_CLIENT_OPT},
50dc83
+    {.key = "features.cloudsync-store-id",
50dc83
+     .voltype = "features/cloudsync",
50dc83
+     .op_version = GD_OP_VERSION_7_0,
50dc83
+     .flags = VOLOPT_FLAG_CLIENT_OPT},
50dc83
+    {.key = "features.cloudsync-product-id",
50dc83
+     .voltype = "features/cloudsync",
50dc83
+     .op_version = GD_OP_VERSION_7_0,
50dc83
      .flags = VOLOPT_FLAG_CLIENT_OPT},
50dc83
     {.key = NULL}};
50dc83
-- 
50dc83
1.8.3.1
50dc83