"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/meta/src/subvolumes-dir.c" (16 Sep 2020, 1596 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "subvolumes-dir.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2014 Red Hat, Inc. <http://www.redhat.com>
    3    This file is part of GlusterFS.
    4 
    5    This file is licensed to you under your choice of the GNU Lesser
    6    General Public License, version 3 or any later version (LGPLv3 or
    7    later), or the GNU General Public License, version 2 (GPLv2), in all
    8    cases as published by the Free Software Foundation.
    9 */
   10 
   11 #include <glusterfs/xlator.h>
   12 #include <glusterfs/defaults.h>
   13 
   14 #include "meta-mem-types.h"
   15 #include "meta.h"
   16 #include "meta-hooks.h"
   17 
   18 static int
   19 subvolumes_dir_fill(xlator_t *this, inode_t *dir, struct meta_dirent **dp)
   20 {
   21     struct meta_dirent *dirents = NULL;
   22     xlator_t *xl = NULL;
   23     xlator_list_t *subv = NULL;
   24     int i = 0;
   25     int count = 0;
   26 
   27     xl = meta_ctx_get(dir, this);
   28 
   29     for (subv = xl->children; subv; subv = subv->next)
   30         count++;
   31 
   32     dirents = GF_MALLOC(sizeof(*dirents) * count, gf_meta_mt_dirents_t);
   33     if (!dirents)
   34         return -1;
   35 
   36     for (subv = xl->children; subv; subv = subv->next) {
   37         char num[16] = {};
   38         snprintf(num, 16, "%d", i);
   39 
   40         dirents[i].name = gf_strdup(num);
   41         dirents[i].type = IA_IFLNK;
   42         dirents[i].hook = meta_subvolume_link_hook;
   43         i++;
   44     }
   45 
   46     *dp = dirents;
   47 
   48     return count;
   49 }
   50 
   51 static struct meta_ops subvolumes_dir_ops = {.dir_fill = subvolumes_dir_fill};
   52 
   53 int
   54 meta_subvolumes_dir_hook(call_frame_t *frame, xlator_t *this, loc_t *loc,
   55                          dict_t *xdata)
   56 {
   57     meta_ctx_set(loc->inode, this, meta_ctx_get(loc->parent, this));
   58 
   59     meta_ops_set(loc->inode, this, &subvolumes_dir_ops);
   60 
   61     return 0;
   62 }