<commit_before>/*
   Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com>
   This file is part of GlusterFS.

   GlusterFS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
   by the Free Software Foundation; either version 3 of the License,
   or (at your option) any later version.

   GlusterFS is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see
   <http://www.gnu.org/licenses/>.
*/

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#ifndef _DHT_H
#define _DHT_H


typedef int (*dht_selfheal_dir_cbk_t) (call_frame_t *frame, void *cookie,
				       xlator_t *this,
				       int32_t op_ret, int32_t op_errno);


struct dht_layout {
        int               cnt;
	int               preset;
        int               gen;
	int               type;
        int               ref;   /* use with dht_conf_t->layout_lock */
        struct {
		int       err;   /* 0 = normal
				   -1 = dir exists and no xattr
				   >0 = dir lookup failed with errno
				 */
                uint32_t  start;
                uint32_t  stop;
                xlator_t *xlator;
        } list[0];
};
typedef struct dht_layout dht_layout_t;


typedef enum {
	DHT_HASH_TYPE_DM,
} dht_hashfn_type_t;


struct dht_local {
	int                      call_cnt;
	loc_t                    loc;
	loc_t                    loc2;
	int                      op_ret;
	int                      op_errno;
	int                      layout_mismatch;
        /* Use stbuf as the postbuf, when we require both
         * pre and post attrs */
	struct stat              stbuf;
        struct stat              prebuf;
        struct stat              preoldparent;
        struct stat              postoldparent; 
        struct stat              preparent;
        struct stat              postparent;
	struct statvfs           statvfs;
	fd_t                    *fd;
	inode_t                 *inode;
	dict_t                  *xattr;
	dict_t                  *xattr_req;
	dht_layout_t            *layout;
	size_t                   size;
	ino_t                    st_ino;
        ino_t                    st_dev;
	xlator_t                *src_hashed, *src_cached;
	xlator_t                *dst_hashed, *dst_cached;
	xlator_t                *cached_subvol;
	xlator_t                *hashed_subvol;
	char                     need_selfheal;
        int                      file_count;
        int                      dir_count;
	struct {
		fop_mknod_cbk_t  linkfile_cbk;
		struct stat      stbuf;
		loc_t            loc;
		inode_t         *inode;
		dict_t          *xattr;
		xlator_t        *srcvol;
	} linkfile;
	struct {
		uint32_t         hole_cnt;
		uint32_t         overlaps_cnt;
		uint32_t         missing;
		uint32_t         down;
		uint32_t         misc;
		dht_selfheal_dir_cbk_t   dir_cbk;
		dht_layout_t    *layout;
	} selfheal;

	/* needed by nufa */
	int32_t flags;
	mode_t  mode;
	dev_t   rdev;
};
typedef struct dht_local dht_local_t;

/* du - disk-usage */
struct dht_du {
        double   avail_percent;
        uint64_t avail_space;
        uint32_t log;
};
typedef struct dht_du dht_du_t;

struct dht_conf {
	gf_lock_t      subvolume_lock;
        int            subvolume_cnt;
        xlator_t     **subvolumes;
	char          *subvolume_status;
	dht_layout_t **file_layouts;
	dht_layout_t **dir_layouts;
	dht_layout_t  *default_dir_layout;
	gf_boolean_t   search_unhashed;
	int            gen;
        dht_du_t      *du_stats;
        uint64_t       min_free_disk;
        char           disk_unit;
        int32_t        refresh_interval;
        gf_boolean_t   unhashed_sticky_bit;
	struct timeval last_stat_fetch;
        gf_lock_t      layout_lock;
        void          *private;     /* Can be used by wrapper xlators over
                                       dht */
};
typedef struct dht_conf dht_conf_t;


struct dht_disk_layout {
	uint32_t           cnt;
	uint32_t           type;
	struct {
		uint32_t   start;
		uint32_t   stop;
	} list[1];
};
typedef struct dht_disk_layout dht_disk_layout_t;
 
#define ENTRY_MISSING(op_ret, op_errno) (op_ret == -1 && op_errno == ENOENT)

#define is_fs_root(loc) (strcmp (loc->path, "/") == 0)

#define is_revalidate(loc) (inode_ctx_get (loc->inode, this, NULL) == 0)

#define is_last_call(cnt) (cnt == 0)

#define DHT_LINKFILE_MODE (S_ISVTX)
#define check_is_linkfile(i,s,x) ((s->st_mode & ~S_IFMT) == DHT_LINKFILE_MODE)

#define check_is_dir(i,s,x) (S_ISDIR(s->st_mode))

#define layout_is_sane(layout) ((layout) && (layout->cnt > 0))
<commit_msg>cluster/dht: Check for size 0 in check_is_linkfile()<commit_after>/*
   Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com>
   This file is part of GlusterFS.

   GlusterFS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
   by the Free Software Foundation; either version 3 of the License,
   or (at your option) any later version.

   GlusterFS is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see
   <http://www.gnu.org/licenses/>.
*/

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#ifndef _DHT_H
#define _DHT_H


typedef int (*dht_selfheal_dir_cbk_t) (call_frame_t *frame, void *cookie,
				       xlator_t *this,
				       int32_t op_ret, int32_t op_errno);


struct dht_layout {
        int               cnt;
	int               preset;
        int               gen;
	int               type;
        int               ref;   /* use with dht_conf_t->layout_lock */
        struct {
		int       err;   /* 0 = normal
				   -1 = dir exists and no xattr
				   >0 = dir lookup failed with errno
				 */
                uint32_t  start;
                uint32_t  stop;
                xlator_t *xlator;
        } list[0];
};
typedef struct dht_layout dht_layout_t;


typedef enum {
	DHT_HASH_TYPE_DM,
} dht_hashfn_type_t;


struct dht_local {
	int                      call_cnt;
	loc_t                    loc;
	loc_t                    loc2;
	int                      op_ret;
	int                      op_errno;
	int                      layout_mismatch;
        /* Use stbuf as the postbuf, when we require both
         * pre and post attrs */
	struct stat              stbuf;
        struct stat              prebuf;
        struct stat              preoldparent;
        struct stat              postoldparent; 
        struct stat              preparent;
        struct stat              postparent;
	struct statvfs           statvfs;
	fd_t                    *fd;
	inode_t                 *inode;
	dict_t                  *xattr;
	dict_t                  *xattr_req;
	dht_layout_t            *layout;
	size_t                   size;
	ino_t                    st_ino;
        ino_t                    st_dev;
	xlator_t                *src_hashed, *src_cached;
	xlator_t                *dst_hashed, *dst_cached;
	xlator_t                *cached_subvol;
	xlator_t                *hashed_subvol;
	char                     need_selfheal;
        int                      file_count;
        int                      dir_count;
	struct {
		fop_mknod_cbk_t  linkfile_cbk;
		struct stat      stbuf;
		loc_t            loc;
		inode_t         *inode;
		dict_t          *xattr;
		xlator_t        *srcvol;
	} linkfile;
	struct {
		uint32_t         hole_cnt;
		uint32_t         overlaps_cnt;
		uint32_t         missing;
		uint32_t         down;
		uint32_t         misc;
		dht_selfheal_dir_cbk_t   dir_cbk;
		dht_layout_t    *layout;
	} selfheal;

	/* needed by nufa */
	int32_t flags;
	mode_t  mode;
	dev_t   rdev;
};
typedef struct dht_local dht_local_t;

/* du - disk-usage */
struct dht_du {
        double   avail_percent;
        uint64_t avail_space;
        uint32_t log;
};
typedef struct dht_du dht_du_t;

struct dht_conf {
	gf_lock_t      subvolume_lock;
        int            subvolume_cnt;
        xlator_t     **subvolumes;
	char          *subvolume_status;
	dht_layout_t **file_layouts;
	dht_layout_t **dir_layouts;
	dht_layout_t  *default_dir_layout;
	gf_boolean_t   search_unhashed;
	int            gen;
        dht_du_t      *du_stats;
        uint64_t       min_free_disk;
        char           disk_unit;
        int32_t        refresh_interval;
        gf_boolean_t   unhashed_sticky_bit;
	struct timeval last_stat_fetch;
        gf_lock_t      layout_lock;
        void          *private;     /* Can be used by wrapper xlators over
                                       dht */
};
typedef struct dht_conf dht_conf_t;


struct dht_disk_layout {
	uint32_t           cnt;
	uint32_t           type;
	struct {
		uint32_t   start;
		uint32_t   stop;
	} list[1];
};
typedef struct dht_disk_layout dht_disk_layout_t;
 
#define ENTRY_MISSING(op_ret, op_errno) (op_ret == -1 && op_errno == ENOENT)

#define is_fs_root(loc) (strcmp (loc->path, "/") == 0)

#define is_revalidate(loc) (inode_ctx_get (loc->inode, this, NULL) == 0)

#define is_last_call(cnt) (cnt == 0)

#define DHT_LINKFILE_MODE (S_ISVTX)
#define check_is_linkfile(i,s,x) (                              \
                ((s->st_mode & ~S_IFMT) == DHT_LINKFILE_MODE) && \
                (s->st_size == 0))

#define check_is_dir(i,s,x) (S_ISDIR(s->st_mode))

#define layout_is_sane(layout) ((layout) && (layout->cnt > 0))

{'fraction_non_alphanumeric': 0.06986190089358245, 'fraction_numerical': 0.01157595450852965, 'mean_word_length': 1.7350735906692585, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6067372', 'n_tokens_mistral': 3480, 'n_tokens_neox': 3229, 'n_words': 854}