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