Expires: Wed, 13 Feb 2036 17:47:46 GMT ETag: "ae8cdb2ad24a70eadf77ef6ba3ed0447e621c272" /* Copyright (c) 2008-2012 Red Hat, Inc. This file is part of GlusterFS. This file is licensed to you under your choice of the GNU Lesser General Public License, version 3 or any later version (LGPLv3 or later), or the GNU General Public License, version 2 (GPLv2), in all cases as published by the Free Software Foundation. */ #include #include #ifndef _CONFIG_H #define _CONFIG_H #include "config.h" #endif #include "glusterfs.h" #include "xlator.h" #include "logging.h" #include "defaults.h" #include "crypt-common.h" #include "crypt.h" static void init_inode_info_head(struct crypt_inode_info *info, fd_t *fd); static int32_t init_inode_info_tail(struct crypt_inode_info *info, struct master_cipher_info *master); static int32_t prepare_for_submit_hole(call_frame_t *frame, xlator_t *this, uint64_t from, off_t size); static int32_t load_file_size(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata); static void do_ordered_submit(call_frame_t *frame, xlator_t *this, atom_data_type dtype); static void do_parallel_submit(call_frame_t *frame, xlator_t *this, atom_data_type dtype); static void put_one_call_open(call_frame_t *frame); static void put_one_call_readv(call_frame_t *frame, xlator_t *this); static void put_one_call_writev(call_frame_t *frame, xlator_t *this); static void put_one_call_ftruncate(call_frame_t *frame, xlator_t *this); static void free_avec(struct iovec *avec, char **pool, int blocks_in_pool); static void free_avec_data(crypt_local_t *local); static void free_avec_hole(crypt_local_t *local); static crypt_local_t *crypt_alloc_local(call_frame_t *frame, xlator_t *this, glusterfs_fop_t fop) { crypt_local_t *local = NULL; local = mem_get0(this->local_pool); if (!local) { gf_log(this->name, GF_LOG_ERROR, "out of memory"); return NULL; } local->fop = fop; LOCK_INIT(&local->hole_lock); LOCK_INIT(&local->call_lock); LOCK_INIT(&local->rw_count_lock); frame->local = local; return local; } struct crypt_inode_info *get_crypt_inode_info(inode_t *inode, xlator_t *this) { int ret; uint64_t value = 0; struct crypt_inode_info *info; ret = inode_ctx_get(inode, this, &value); if (ret == -1) { gf_log (this->name, GF_LOG_WARNING, "Can not get inode info"); return NULL; } info = (struct crypt_inode_info *)(long)value; if (info == NULL) { gf_log (this->name, GF_LOG_WARNING, "Can not obtain inode info"); return NULL; } return info; } static struct crypt_inode_info *local_get_inode_info(crypt_local_t *local, xlator_t *this) { if (local->info) return local->info; local->info = get_crypt_inode_info(local->fd->inode, this); return local->info; } static struct crypt_inode_info *alloc_inode_info(crypt_local_t *local, loc_t *loc) { struct crypt_inode_info *info; info = GF_CALLOC(1, sizeof(*info), gf_crypt_mt_inode); if (!info) { local->op_ret = -1; local->op_errno = ENOMEM; gf_log ("crypt", GF_LOG_WARNING, "Can not allocate inode info"); return NULL; } memset(info, 0, sizeof(*info)); #if DEBUG_CRYPT info->loc = GF_CALLOC(1, sizeof(*loc), gf_crypt_mt_loc); if (!info->loc) { gf_log("crypt", GF_LOG_WARNING, "Can not allocate loc"); GF_FREE(info); return NULL; } if (loc_copy(info->loc, loc)){ GF_FREE(info->loc); GF_FREE(info); return NULL; } #endif /* DEBUG_CRYPT */ local->info = info; return info; } static void free_inode_info(struct crypt_inode_info *info) { #if DEBUG_CRYPT loc_wipe(info->loc); GF_FREE(info->loc); #endif memset(info, 0, siz