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