nfs-ganesha 1.4

fsal_context.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright (C) 2010, The Linux Box Corporation
00005  * Contributor : Adam C. Emerson <aemerson@linuxbox.com>
00006  *
00007  * Some portions Copyright CEA/DAM/DIF  (2008)
00008  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00009  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00010  *
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 3 of the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00025  *
00026  * -------------
00027  */
00028 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #include "fsal.h"
00040 #include "fsal_internal.h"
00041 #include <pwd.h>
00042 #include <errno.h>
00043 #include <stdlib.h>
00044 #include <string.h>
00045 
00058 fsal_status_t CEPHFSAL_BuildExportContext(
00059                        fsal_export_context_t * export_context,
00060                        fsal_path_t * export_path,
00061                        char *fs_specific_options)
00062 {
00063     cephfsal_export_context_t* ceph_export_context =
00064         (cephfsal_export_context_t*) export_context;
00065     char *argv[2];
00066     int argc=1;
00067     int rc;
00068 
00069     char procname[]="FSAL_CEPH";
00070 
00071     /* allocates ceph_mount_info */
00072     rc = ceph_create(&ceph_export_context->cmount, NULL);
00073     if (rc)
00074         Return(ERR_FSAL_SERVERFAULT, 0, INDEX_FSAL_BuildExportContext);
00075 
00076     ceph_conf_read_file(ceph_export_context->cmount, NULL);
00077 
00078     /* The mountspec we pass to Ceph's init */
00079     if (snprintf(ceph_export_context->mount, FSAL_MAX_PATH_LEN, "%s:%s",
00080                  global_spec_info.cephserver, export_path->path) >=
00081         FSAL_MAX_PATH_LEN)
00082         Return(ERR_FSAL_NAMETOOLONG, 0, INDEX_FSAL_BuildExportContext);
00083 
00084     /* This has worked so far. */
00085     argv[0] = procname;
00086     argv[1] = ceph_export_context->mount;
00087 
00088     ceph_conf_parse_argv(ceph_export_context->cmount, argc,
00089                          (const char**) argv);
00090 
00091     rc = ceph_mount(ceph_export_context->cmount, NULL);
00092     if (rc)
00093         Return(ERR_FSAL_SERVERFAULT, 0, INDEX_FSAL_InitClientContext);
00094 
00095   /* Save pointer to fsal_staticfsinfo_t in export context */
00096   export_context->fe_static_fs_info = &global_fs_info;
00097 
00098   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_BuildExportContext);
00099 }
00100 
00109 fsal_status_t CEPHFSAL_CleanUpExportContext(
00110                               fsal_export_context_t *export_context)
00111 {
00112   cephfsal_export_context_t* ceph_export_context =
00113     (cephfsal_export_context_t*) export_context;
00114 
00115   /* clean up and dispose Ceph mount */
00116   ceph_shutdown(ceph_export_context->cmount);
00117 
00118   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_CleanUpExportContext);
00119 }
00120 
00121 /* @} */
00122