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