^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * xattr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2004, 2008 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * CREDITS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Lots of code in this file is copy from linux/fs/ext3/xattr.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/splice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/falloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/sort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <cluster/masklog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "ocfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "blockcheck.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "dlmglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "file.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "symlink.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "sysfile.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "journal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "ocfs2_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "suballoc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include "uptodate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include "buffer_head_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include "refcounttree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include "ocfs2_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct ocfs2_xattr_def_value_root {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct ocfs2_xattr_value_root xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct ocfs2_extent_rec er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct ocfs2_xattr_bucket {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* The inode these xattrs are associated with */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct inode *bu_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* The actual buffers that make up the bucket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct buffer_head *bu_bhs[OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* How many blocks make up one bucket for this filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int bu_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct ocfs2_xattr_set_ctxt {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct ocfs2_alloc_context *meta_ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct ocfs2_alloc_context *data_ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct ocfs2_cached_dealloc_ctxt dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int set_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define OCFS2_XATTR_ROOT_SIZE (sizeof(struct ocfs2_xattr_def_value_root))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define OCFS2_XATTR_INLINE_SIZE 80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define OCFS2_XATTR_HEADER_GAP 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define OCFS2_XATTR_FREE_IN_IBODY (OCFS2_MIN_XATTR_INLINE_SIZE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) - sizeof(struct ocfs2_xattr_header) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) - OCFS2_XATTR_HEADER_GAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define OCFS2_XATTR_FREE_IN_BLOCK(ptr) ((ptr)->i_sb->s_blocksize \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) - sizeof(struct ocfs2_xattr_block) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) - sizeof(struct ocfs2_xattr_header) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) - OCFS2_XATTR_HEADER_GAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct ocfs2_xattr_def_value_root def_xv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .xv.xr_list.l_count = cpu_to_le16(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) const struct xattr_handler *ocfs2_xattr_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) &ocfs2_xattr_user_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) &posix_acl_access_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) &posix_acl_default_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) &ocfs2_xattr_trusted_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) &ocfs2_xattr_security_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static const struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) [OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) = &posix_acl_access_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) [OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) = &posix_acl_default_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) [OCFS2_XATTR_INDEX_SECURITY] = &ocfs2_xattr_security_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct ocfs2_xattr_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int xi_name_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) const char *xi_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int xi_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) const void *xi_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) size_t xi_value_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct ocfs2_xattr_search {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct buffer_head *inode_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * xattr_bh point to the block buffer head which has extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * when extended attribute in inode, xattr_bh is equal to inode_bh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct buffer_head *xattr_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct ocfs2_xattr_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct ocfs2_xattr_bucket *bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) void *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct ocfs2_xattr_entry *here;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Operations on struct ocfs2_xa_entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct ocfs2_xa_loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct ocfs2_xa_loc_operations {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * Journal functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int (*xlo_journal_access)(handle_t *handle, struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void (*xlo_journal_dirty)(handle_t *handle, struct ocfs2_xa_loc *loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Return a pointer to the appropriate buffer in loc->xl_storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * at the given offset from loc->xl_header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) void *(*xlo_offset_pointer)(struct ocfs2_xa_loc *loc, int offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* Can we reuse the existing entry for the new value? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int (*xlo_can_reuse)(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct ocfs2_xattr_info *xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* How much space is needed for the new value? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int (*xlo_check_space)(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct ocfs2_xattr_info *xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Return the offset of the first name+value pair. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * the start of our downward-filling free space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int (*xlo_get_free_start)(struct ocfs2_xa_loc *loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Remove the name+value at this location. Do whatever is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * appropriate with the remaining name+value pairs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void (*xlo_wipe_namevalue)(struct ocfs2_xa_loc *loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Fill xl_entry with a new entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) void (*xlo_add_entry)(struct ocfs2_xa_loc *loc, u32 name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* Add name+value storage to an entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) void (*xlo_add_namevalue)(struct ocfs2_xa_loc *loc, int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Initialize the value buf's access and bh fields for this entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * ocfs2_xa_fill_value_buf() will handle the xv pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void (*xlo_fill_value_buf)(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct ocfs2_xattr_value_buf *vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Describes an xattr entry location. This is a memory structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * tracking the on-disk structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct ocfs2_xa_loc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* This xattr belongs to this inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct inode *xl_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* The ocfs2_xattr_header inside the on-disk storage. Not NULL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct ocfs2_xattr_header *xl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* Bytes from xl_header to the end of the storage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int xl_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * The ocfs2_xattr_entry this location describes. If this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * NULL, this location describes the on-disk structure where it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * would have been.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct ocfs2_xattr_entry *xl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Internal housekeeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* Buffer(s) containing this entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) void *xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* Operations on the storage backing this location */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) const struct ocfs2_xa_loc_operations *xl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * Convenience functions to calculate how much space is needed for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * given name+value pair
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int namevalue_size(int name_len, uint64_t value_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (value_len > OCFS2_XATTR_INLINE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_SIZE(value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int namevalue_size_xi(struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return namevalue_size(xi->xi_name_len, xi->xi_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int namevalue_size_xe(struct ocfs2_xattr_entry *xe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) u64 value_len = le64_to_cpu(xe->xe_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) BUG_ON((value_len > OCFS2_XATTR_INLINE_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ocfs2_xattr_is_local(xe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return namevalue_size(xe->xe_name_len, value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int *block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int *new_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int ocfs2_xattr_block_find(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct ocfs2_xattr_search *xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int ocfs2_xattr_index_block_find(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct ocfs2_xattr_search *xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int ocfs2_xattr_tree_list_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct buffer_head *blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) size_t buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static int ocfs2_xattr_create_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct ocfs2_xattr_set_ctxt *ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int ocfs2_xattr_set_entry_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct ocfs2_xattr_set_ctxt *ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) typedef int (xattr_tree_rec_func)(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) u64 blkno, u32 cpos, u32 len, void *para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static int ocfs2_iterate_xattr_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) xattr_tree_rec_func *rec_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) void *para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int ocfs2_delete_xattr_in_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) void *para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int ocfs2_rm_xattr_cluster(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) u64 blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) u32 cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) void *para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int ocfs2_mv_xattr_buckets(struct inode *inode, handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) u64 src_blk, u64 last_blk, u64 to_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) unsigned int start_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) u32 *first_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static int ocfs2_prepare_refcount_xattr(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct ocfs2_dinode *di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct ocfs2_xattr_search *xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct ocfs2_xattr_search *xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct ocfs2_refcount_tree **ref_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int *meta_need,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int *credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static int ocfs2_get_xattr_tree_value_root(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct ocfs2_xattr_value_root **xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct buffer_head **bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return (1 << osb->s_clustersize_bits) / OCFS2_XATTR_BUCKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline u16 ocfs2_blocks_per_xattr_bucket(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return OCFS2_XATTR_BUCKET_SIZE / (1 << sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #define bucket_blkno(_b) ((_b)->bu_bhs[0]->b_blocknr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #define bucket_block(_b, _n) ((_b)->bu_bhs[(_n)]->b_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #define bucket_xh(_b) ((struct ocfs2_xattr_header *)bucket_block((_b), 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static struct ocfs2_xattr_bucket *ocfs2_xattr_bucket_new(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct ocfs2_xattr_bucket *bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) BUG_ON(blks > OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) bucket = kzalloc(sizeof(struct ocfs2_xattr_bucket), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) bucket->bu_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) bucket->bu_blocks = blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static void ocfs2_xattr_bucket_relse(struct ocfs2_xattr_bucket *bucket)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) for (i = 0; i < bucket->bu_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) brelse(bucket->bu_bhs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) bucket->bu_bhs[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void ocfs2_xattr_bucket_free(struct ocfs2_xattr_bucket *bucket)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ocfs2_xattr_bucket_relse(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) bucket->bu_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) kfree(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * A bucket that has never been written to disk doesn't need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * read. We just need the buffer_heads. Don't call this for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * buckets that are already on disk. ocfs2_read_xattr_bucket() initializes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * them fully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static int ocfs2_init_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) u64 xb_blkno, int new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) int i, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) for (i = 0; i < bucket->bu_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) bucket->bu_bhs[i] = sb_getblk(bucket->bu_inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) xb_blkno + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (!bucket->bu_bhs[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (!ocfs2_buffer_uptodate(INODE_CACHE(bucket->bu_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) bucket->bu_bhs[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ocfs2_set_new_buffer_uptodate(INODE_CACHE(bucket->bu_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) bucket->bu_bhs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) set_buffer_uptodate(bucket->bu_bhs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ocfs2_set_buffer_uptodate(INODE_CACHE(bucket->bu_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) bucket->bu_bhs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ocfs2_xattr_bucket_relse(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* Read the xattr bucket at xb_blkno */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int ocfs2_read_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) u64 xb_blkno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) rc = ocfs2_read_blocks(INODE_CACHE(bucket->bu_inode), xb_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) bucket->bu_blocks, bucket->bu_bhs, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) spin_lock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) rc = ocfs2_validate_meta_ecc_bhs(bucket->bu_inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) bucket->bu_bhs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) bucket->bu_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) &bucket_xh(bucket)->xh_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) spin_unlock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ocfs2_xattr_bucket_relse(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static int ocfs2_xattr_bucket_journal_access(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) int i, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) for (i = 0; i < bucket->bu_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) rc = ocfs2_journal_access(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) INODE_CACHE(bucket->bu_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) bucket->bu_bhs[i], type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static void ocfs2_xattr_bucket_journal_dirty(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct ocfs2_xattr_bucket *bucket)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) spin_lock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ocfs2_compute_meta_ecc_bhs(bucket->bu_inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) bucket->bu_bhs, bucket->bu_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) &bucket_xh(bucket)->xh_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) spin_unlock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) for (i = 0; i < bucket->bu_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) ocfs2_journal_dirty(handle, bucket->bu_bhs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static void ocfs2_xattr_bucket_copy_data(struct ocfs2_xattr_bucket *dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct ocfs2_xattr_bucket *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) int blocksize = src->bu_inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) BUG_ON(dest->bu_blocks != src->bu_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) BUG_ON(dest->bu_inode != src->bu_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) for (i = 0; i < src->bu_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) memcpy(bucket_block(dest, i), bucket_block(src, i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static int ocfs2_validate_xattr_block(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) (struct ocfs2_xattr_block *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) trace_ocfs2_validate_xattr_block((unsigned long long)bh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) BUG_ON(!buffer_uptodate(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * If the ecc fails, we return the error but otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * leave the filesystem running. We know any error is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * local to this block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &xb->xb_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * Errors after here are fatal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return ocfs2_error(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) "Extended attribute block #%llu has bad signature %.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) (unsigned long long)bh->b_blocknr, 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) xb->xb_signature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (le64_to_cpu(xb->xb_blkno) != bh->b_blocknr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return ocfs2_error(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) "Extended attribute block #%llu has an invalid xb_blkno of %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) (unsigned long long)bh->b_blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) (unsigned long long)le64_to_cpu(xb->xb_blkno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (le32_to_cpu(xb->xb_fs_generation) != OCFS2_SB(sb)->fs_generation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return ocfs2_error(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) "Extended attribute block #%llu has an invalid xb_fs_generation of #%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) (unsigned long long)bh->b_blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) le32_to_cpu(xb->xb_fs_generation));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static int ocfs2_read_xattr_block(struct inode *inode, u64 xb_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct buffer_head **bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct buffer_head *tmp = *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) rc = ocfs2_read_block(INODE_CACHE(inode), xb_blkno, &tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) ocfs2_validate_xattr_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /* If ocfs2_read_block() got us a new bh, pass it up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (!rc && !*bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) *bh = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static inline const char *ocfs2_xattr_prefix(int name_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) const struct xattr_handler *handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (name_index > 0 && name_index < OCFS2_XATTR_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) handler = ocfs2_xattr_handler_map[name_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return handler ? xattr_prefix(handler) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static u32 ocfs2_xattr_name_hash(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /* Get hash value of uuid from super block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) u32 hash = OCFS2_SB(inode->i_sb)->uuid_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /* hash extended attribute name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) for (i = 0; i < name_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) hash = (hash << OCFS2_HASH_SHIFT) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) (hash >> (8*sizeof(hash) - OCFS2_HASH_SHIFT)) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) *name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static int ocfs2_xattr_entry_real_size(int name_len, size_t value_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return namevalue_size(name_len, value_len) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) sizeof(struct ocfs2_xattr_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static int ocfs2_xi_entry_usage(struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return namevalue_size_xi(xi) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) sizeof(struct ocfs2_xattr_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static int ocfs2_xe_entry_usage(struct ocfs2_xattr_entry *xe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return namevalue_size_xe(xe) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) sizeof(struct ocfs2_xattr_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) int ocfs2_calc_security_init(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) struct ocfs2_security_xattr_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) int *want_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) int *xattr_credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct ocfs2_alloc_context **xattr_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) int s_size = ocfs2_xattr_entry_real_size(strlen(si->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) si->value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * The max space of security xattr taken inline is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * 256(name) + 80(value) + 16(entry) = 352 bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * So reserve one metadata block for it is ok.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) s_size > OCFS2_XATTR_FREE_IN_IBODY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) ret = ocfs2_reserve_new_metadata_blocks(osb, 1, xattr_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) *xattr_credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* reserve clusters for xattr value which will be set in B tree*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (si->value_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) int new_clusters = ocfs2_clusters_for_bytes(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) si->value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) *xattr_credits += ocfs2_clusters_to_blocks(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) new_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) *want_clusters += new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) int ocfs2_calc_xattr_init(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct buffer_head *dir_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct ocfs2_security_xattr_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) int *want_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) int *xattr_credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) int *want_meta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) int s_size = 0, a_size = 0, acl_len = 0, new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (si->enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) s_size = ocfs2_xattr_entry_real_size(strlen(si->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) si->value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) down_read(&OCFS2_I(dir)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) acl_len = ocfs2_xattr_get_nolock(dir, dir_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) "", NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) up_read(&OCFS2_I(dir)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (acl_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) a_size = ocfs2_xattr_entry_real_size(0, acl_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (S_ISDIR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) a_size <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) } else if (acl_len != 0 && acl_len != -ENODATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) ret = acl_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (!(s_size + a_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * The max space of security xattr taken inline is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * 256(name) + 80(value) + 16(entry) = 352 bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * The max space of acl xattr taken inline is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * 80(value) + 16(entry) * 2(if directory) = 192 bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * when blocksize = 512, may reserve one more cluser for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * xattr bucket, otherwise reserve one metadata block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) * for them is ok.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) * If this is a new directory with inline data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) * we choose to reserve the entire inline area for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * directory contents and force an external xattr block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) (S_ISDIR(mode) && ocfs2_supports_inline_data(osb)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) (s_size + a_size) > OCFS2_XATTR_FREE_IN_IBODY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) *want_meta = *want_meta + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) *xattr_credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) (s_size + a_size) > OCFS2_XATTR_FREE_IN_BLOCK(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) *want_clusters += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) *xattr_credits += ocfs2_blocks_per_xattr_bucket(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * reserve credits and clusters for xattrs which has large value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * and have to be set outside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (si->enable && si->value_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) new_clusters = ocfs2_clusters_for_bytes(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) si->value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) *xattr_credits += ocfs2_clusters_to_blocks(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) new_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) *want_clusters += new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) acl_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /* for directory, it has DEFAULT and ACCESS two types of acls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) new_clusters = (S_ISDIR(mode) ? 2 : 1) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) ocfs2_clusters_for_bytes(dir->i_sb, acl_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) *xattr_credits += ocfs2_clusters_to_blocks(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) new_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) *want_clusters += new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) static int ocfs2_xattr_extend_allocation(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) u32 clusters_to_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) int status = 0, credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) handle_t *handle = ctxt->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) enum ocfs2_alloc_restarted why;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) u32 prev_clusters, logical_start = le32_to_cpu(vb->vb_xv->xr_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) struct ocfs2_extent_tree et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) ocfs2_init_xattr_value_extent_tree(&et, INODE_CACHE(inode), vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) while (clusters_to_add) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) trace_ocfs2_xattr_extend_allocation(clusters_to_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) status = vb->vb_access(handle, INODE_CACHE(inode), vb->vb_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) prev_clusters = le32_to_cpu(vb->vb_xv->xr_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) status = ocfs2_add_clusters_in_btree(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) &et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) &logical_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) clusters_to_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) ctxt->data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) ctxt->meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) &why);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if ((status < 0) && (status != -EAGAIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (status != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) ocfs2_journal_dirty(handle, vb->vb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) clusters_to_add -= le32_to_cpu(vb->vb_xv->xr_clusters) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) prev_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (why != RESTART_NONE && clusters_to_add) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * We can only fail in case the alloc file doesn't give
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * up enough clusters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) BUG_ON(why == RESTART_META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) credits = ocfs2_calc_extend_credits(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) &vb->vb_xv->xr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) status = ocfs2_extend_trans(handle, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) static int __ocfs2_remove_xattr_range(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) u32 cpos, u32 phys_cpos, u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) unsigned int ext_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) handle_t *handle = ctxt->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) struct ocfs2_extent_tree et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) ocfs2_init_xattr_value_extent_tree(&et, INODE_CACHE(inode), vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ret = vb->vb_access(handle, INODE_CACHE(inode), vb->vb_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) ret = ocfs2_remove_extent(handle, &et, cpos, len, ctxt->meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) &ctxt->dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) le32_add_cpu(&vb->vb_xv->xr_clusters, -len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) ocfs2_journal_dirty(handle, vb->vb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (ext_flags & OCFS2_EXT_REFCOUNTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) ret = ocfs2_decrease_refcount(inode, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) ocfs2_blocks_to_clusters(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) phys_blkno),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) len, ctxt->meta_ac, &ctxt->dealloc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) ret = ocfs2_cache_cluster_dealloc(&ctxt->dealloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) phys_blkno, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) static int ocfs2_xattr_shrink_size(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) u32 old_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) u32 new_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) unsigned int ext_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) u32 trunc_len, cpos, phys_cpos, alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) u64 block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (old_clusters <= new_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) cpos = new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) trunc_len = old_clusters - new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) while (trunc_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ret = ocfs2_xattr_get_clusters(inode, cpos, &phys_cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) &alloc_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) &vb->vb_xv->xr_list, &ext_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (alloc_size > trunc_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) alloc_size = trunc_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) ret = __ocfs2_remove_xattr_range(inode, vb, cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) phys_cpos, alloc_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) ext_flags, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) block = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) ocfs2_remove_xattr_clusters_from_cache(INODE_CACHE(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) block, alloc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) cpos += alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) trunc_len -= alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) static int ocfs2_xattr_value_truncate(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) u32 new_clusters = ocfs2_clusters_for_bytes(inode->i_sb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) u32 old_clusters = le32_to_cpu(vb->vb_xv->xr_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (new_clusters == old_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (new_clusters > old_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) ret = ocfs2_xattr_extend_allocation(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) new_clusters - old_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) vb, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) ret = ocfs2_xattr_shrink_size(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) old_clusters, new_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) vb, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) static int ocfs2_xattr_list_entry(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) char *buffer, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) size_t *result, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) const char *name, int name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) char *p = buffer + *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) const char *prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) int prefix_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) int total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) switch(type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) case OCFS2_XATTR_INDEX_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) if (OCFS2_SB(sb)->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) case OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) case OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (!(sb->s_flags & SB_POSIXACL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) case OCFS2_XATTR_INDEX_TRUSTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) prefix = ocfs2_xattr_prefix(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (!prefix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) prefix_len = strlen(prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) total_len = prefix_len + name_len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) *result += total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) /* we are just looking for how big our buffer needs to be */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (*result > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) memcpy(p, prefix, prefix_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) memcpy(p + prefix_len, name, name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) p[prefix_len + name_len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) static int ocfs2_xattr_list_entries(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) struct ocfs2_xattr_header *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) char *buffer, size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) size_t result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) int i, type, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) for (i = 0 ; i < le16_to_cpu(header->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) struct ocfs2_xattr_entry *entry = &header->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) type = ocfs2_xattr_get_type(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) name = (const char *)header +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) le16_to_cpu(entry->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) ret = ocfs2_xattr_list_entry(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) buffer, buffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) &result, type, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) entry->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) int ocfs2_has_inline_xattr_value_outside(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) struct ocfs2_dinode *di)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) struct ocfs2_xattr_header *xh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) xh = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) ((void *)di + inode->i_sb->s_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) le16_to_cpu(di->i_xattr_inline_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) for (i = 0; i < le16_to_cpu(xh->xh_count); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (!ocfs2_xattr_is_local(&xh->xh_entries[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) static int ocfs2_xattr_ibody_list(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) struct ocfs2_dinode *di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) struct ocfs2_xattr_header *header = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) header = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) ((void *)di + inode->i_sb->s_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) le16_to_cpu(di->i_xattr_inline_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) ret = ocfs2_xattr_list_entries(inode, header, buffer, buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) static int ocfs2_xattr_block_list(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) struct ocfs2_dinode *di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) struct buffer_head *blk_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) struct ocfs2_xattr_block *xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (!di->i_xattr_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) ret = ocfs2_read_xattr_block(inode, le64_to_cpu(di->i_xattr_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) &blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) struct ocfs2_xattr_header *header = &xb->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) ret = ocfs2_xattr_list_entries(inode, header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) buffer, buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) ret = ocfs2_xattr_tree_list_index_block(inode, blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) buffer, buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) brelse(blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) ssize_t ocfs2_listxattr(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) int ret = 0, i_ret = 0, b_ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) struct buffer_head *di_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) struct ocfs2_dinode *di = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) struct ocfs2_inode_info *oi = OCFS2_I(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) if (!ocfs2_supports_xattr(OCFS2_SB(dentry->d_sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) ret = ocfs2_inode_lock(d_inode(dentry), &di_bh, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) di = (struct ocfs2_dinode *)di_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) down_read(&oi->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) i_ret = ocfs2_xattr_ibody_list(d_inode(dentry), di, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) if (i_ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) b_ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) buffer += i_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) size -= i_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) b_ret = ocfs2_xattr_block_list(d_inode(dentry), di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (b_ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) i_ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) up_read(&oi->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) ocfs2_inode_unlock(d_inode(dentry), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) brelse(di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) return i_ret + b_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) static int ocfs2_xattr_find_entry(int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) struct ocfs2_xattr_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) size_t name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) int i, cmp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (name == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) entry = xs->here;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) for (i = 0; i < le16_to_cpu(xs->header->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) cmp = name_index - ocfs2_xattr_get_type(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (!cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) cmp = name_len - entry->xe_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (!cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) cmp = memcmp(name, (xs->base +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) le16_to_cpu(entry->xe_name_offset)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (cmp == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) entry += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) xs->here = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return cmp ? -ENODATA : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static int ocfs2_xattr_get_value_outside(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) struct ocfs2_xattr_value_root *xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) u32 cpos, p_cluster, num_clusters, bpc, clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) u64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) size_t cplen, blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) struct ocfs2_extent_list *el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) el = &xv->xr_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) clusters = le32_to_cpu(xv->xr_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) cpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) while (cpos < clusters) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) &num_clusters, el, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) /* Copy ocfs2_xattr_value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) for (i = 0; i < num_clusters * bpc; i++, blkno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) ret = ocfs2_read_block(INODE_CACHE(inode), blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) &bh, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) cplen = len >= blocksize ? blocksize : len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) memcpy(buffer, bh->b_data, cplen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) len -= cplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) buffer += cplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) if (len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) cpos += num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) static int ocfs2_xattr_ibody_get(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) size_t buffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) struct ocfs2_xattr_value_root *xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) xs->end = (void *)di + inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) xs->header = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) (xs->end - le16_to_cpu(di->i_xattr_inline_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) xs->base = (void *)xs->header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) xs->here = xs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) ret = ocfs2_xattr_find_entry(name_index, name, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) size = le64_to_cpu(xs->here->xe_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) if (size > buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (ocfs2_xattr_is_local(xs->here)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) memcpy(buffer, (void *)xs->base +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) le16_to_cpu(xs->here->xe_name_offset) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) OCFS2_XATTR_SIZE(xs->here->xe_name_len), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) xv = (struct ocfs2_xattr_value_root *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) (xs->base + le16_to_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) xs->here->xe_name_offset) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) OCFS2_XATTR_SIZE(xs->here->xe_name_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) ret = ocfs2_xattr_get_value_outside(inode, xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) static int ocfs2_xattr_block_get(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) size_t buffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) struct ocfs2_xattr_block *xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) struct ocfs2_xattr_value_root *xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) int ret = -ENODATA, name_offset, name_len, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) int block_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) xs->bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) if (!xs->bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) ret = ocfs2_xattr_block_find(inode, name_index, name, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) if (xs->not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) ret = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) xb = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) size = le64_to_cpu(xs->here->xe_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) ret = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (size > buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) name_offset = le16_to_cpu(xs->here->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) name_len = OCFS2_XATTR_SIZE(xs->here->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) i = xs->here - xs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) bucket_xh(xs->bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) &block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) &name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) xs->base = bucket_block(xs->bucket, block_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) if (ocfs2_xattr_is_local(xs->here)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) memcpy(buffer, (void *)xs->base +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) name_offset + name_len, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) xv = (struct ocfs2_xattr_value_root *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) (xs->base + name_offset + name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) ret = ocfs2_xattr_get_value_outside(inode, xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) ret = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) ocfs2_xattr_bucket_free(xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) brelse(xs->xattr_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) xs->xattr_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) int ocfs2_xattr_get_nolock(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) struct buffer_head *di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) struct ocfs2_dinode *di = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) struct ocfs2_xattr_search xis = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) .not_found = -ENODATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct ocfs2_xattr_search xbs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) .not_found = -ENODATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) xis.inode_bh = xbs.inode_bh = di_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) di = (struct ocfs2_dinode *)di_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) ret = ocfs2_xattr_ibody_get(inode, name_index, name, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) buffer_size, &xis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) if (ret == -ENODATA && di->i_xattr_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) ret = ocfs2_xattr_block_get(inode, name_index, name, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) buffer_size, &xbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) /* ocfs2_xattr_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) * Copy an extended attribute into the buffer provided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) * Buffer is NULL to compute the size of buffer required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) static int ocfs2_xattr_get(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) int ret, had_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) struct buffer_head *di_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) struct ocfs2_lock_holder oh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) had_lock = ocfs2_inode_lock_tracker(inode, &di_bh, 0, &oh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if (had_lock < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) mlog_errno(had_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) return had_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) down_read(&OCFS2_I(inode)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) ret = ocfs2_xattr_get_nolock(inode, di_bh, name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) name, buffer, buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) up_read(&OCFS2_I(inode)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) ocfs2_inode_unlock_tracker(inode, 0, &oh, had_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) brelse(di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) static int __ocfs2_xattr_set_value_outside(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) int value_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) int ret = 0, i, cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) u16 blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) u32 p_cluster, num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) u32 cpos = 0, bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) u32 clusters = ocfs2_clusters_for_bytes(inode->i_sb, value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) u64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) unsigned int ext_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) struct ocfs2_xattr_value_root *xv = vb->vb_xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) BUG_ON(clusters > le32_to_cpu(xv->xr_clusters));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) while (cpos < clusters) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) &num_clusters, &xv->xr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) &ext_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) BUG_ON(ext_flags & OCFS2_EXT_REFCOUNTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) for (i = 0; i < num_clusters * bpc; i++, blkno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) ret = ocfs2_read_block(INODE_CACHE(inode), blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) &bh, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) ret = ocfs2_journal_access(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) INODE_CACHE(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) cp_len = value_len > blocksize ? blocksize : value_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) memcpy(bh->b_data, value, cp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) value_len -= cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) value += cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (cp_len < blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) memset(bh->b_data + cp_len, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) blocksize - cp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) ocfs2_journal_dirty(handle, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) * XXX: do we need to empty all the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) * blocks in this cluster?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (!value_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) cpos += num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) static int ocfs2_xa_check_space_helper(int needed_space, int free_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) int num_entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) int free_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) if (!needed_space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) free_space = free_start -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) sizeof(struct ocfs2_xattr_header) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) (num_entries * sizeof(struct ocfs2_xattr_entry)) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) OCFS2_XATTR_HEADER_GAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) if (free_space < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) if (free_space < needed_space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) static int ocfs2_xa_journal_access(handle_t *handle, struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) return loc->xl_ops->xlo_journal_access(handle, loc, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) static void ocfs2_xa_journal_dirty(handle_t *handle, struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) loc->xl_ops->xlo_journal_dirty(handle, loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) /* Give a pointer into the storage for the given offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) static void *ocfs2_xa_offset_pointer(struct ocfs2_xa_loc *loc, int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) BUG_ON(offset >= loc->xl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) return loc->xl_ops->xlo_offset_pointer(loc, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) * Wipe the name+value pair and allow the storage to reclaim it. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * must be followed by either removal of the entry or a call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) * ocfs2_xa_add_namevalue().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) static void ocfs2_xa_wipe_namevalue(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) loc->xl_ops->xlo_wipe_namevalue(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) * Find lowest offset to a name+value pair. This is the start of our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) * downward-growing free space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) static int ocfs2_xa_get_free_start(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) return loc->xl_ops->xlo_get_free_start(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) /* Can we reuse loc->xl_entry for xi? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) static int ocfs2_xa_can_reuse_entry(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) return loc->xl_ops->xlo_can_reuse(loc, xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) /* How much free space is needed to set the new value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) return loc->xl_ops->xlo_check_space(loc, xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) loc->xl_ops->xlo_add_entry(loc, name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) * We can't leave the new entry's xe_name_offset at zero or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) * add_namevalue() will go nuts. We set it to the size of our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) * storage so that it can never be less than any other entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) int size = namevalue_size_xi(xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) int nameval_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) char *nameval_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) loc->xl_ops->xlo_add_namevalue(loc, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) loc->xl_entry->xe_name_len = xi->xi_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) ocfs2_xattr_set_type(loc->xl_entry, xi->xi_name_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) ocfs2_xattr_set_local(loc->xl_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) nameval_buf = ocfs2_xa_offset_pointer(loc, nameval_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) memset(nameval_buf, 0, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) memcpy(nameval_buf, xi->xi_name, xi->xi_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) static void ocfs2_xa_fill_value_buf(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) struct ocfs2_xattr_value_buf *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) int name_size = OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) /* Value bufs are for value trees */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) BUG_ON(ocfs2_xattr_is_local(loc->xl_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) BUG_ON(namevalue_size_xe(loc->xl_entry) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) (name_size + OCFS2_XATTR_ROOT_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) loc->xl_ops->xlo_fill_value_buf(loc, vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) vb->vb_xv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) (struct ocfs2_xattr_value_root *)ocfs2_xa_offset_pointer(loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) nameval_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) static int ocfs2_xa_block_journal_access(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) struct ocfs2_xa_loc *loc, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) struct buffer_head *bh = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) ocfs2_journal_access_func access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) if (loc->xl_size == (bh->b_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) offsetof(struct ocfs2_xattr_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) xb_attrs.xb_header)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) access = ocfs2_journal_access_xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) access = ocfs2_journal_access_di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) return access(handle, INODE_CACHE(loc->xl_inode), bh, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) static void ocfs2_xa_block_journal_dirty(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) struct buffer_head *bh = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) ocfs2_journal_dirty(handle, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) static void *ocfs2_xa_block_offset_pointer(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) return (char *)loc->xl_header + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) static int ocfs2_xa_block_can_reuse(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) * Block storage is strict. If the sizes aren't exact, we will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) * remove the old one and reinsert the new.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) return namevalue_size_xe(loc->xl_entry) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) namevalue_size_xi(xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) struct ocfs2_xattr_header *xh = loc->xl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) int i, count = le16_to_cpu(xh->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) int offset, free_start = loc->xl_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) if (offset < free_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) free_start = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) return free_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) static int ocfs2_xa_block_check_space(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) int count = le16_to_cpu(loc->xl_header->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) int free_start = ocfs2_xa_get_free_start(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) int needed_space = ocfs2_xi_entry_usage(xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) * Block storage will reclaim the original entry before inserting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) * the new value, so we only need the difference. If the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) * entry is smaller than the old one, we don't need anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) if (loc->xl_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) /* Don't need space if we're reusing! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) if (ocfs2_xa_can_reuse_entry(loc, xi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) needed_space = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) needed_space -= ocfs2_xe_entry_usage(loc->xl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) if (needed_space < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) needed_space = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) return ocfs2_xa_check_space_helper(needed_space, free_start, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) * Block storage for xattrs keeps the name+value pairs compacted. When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) * we remove one, we have to shift any that preceded it towards the end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) static void ocfs2_xa_block_wipe_namevalue(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) int i, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) int namevalue_offset, first_namevalue_offset, namevalue_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) struct ocfs2_xattr_entry *entry = loc->xl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) struct ocfs2_xattr_header *xh = loc->xl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) int count = le16_to_cpu(xh->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) namevalue_offset = le16_to_cpu(entry->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) namevalue_size = namevalue_size_xe(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) first_namevalue_offset = ocfs2_xa_get_free_start(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) /* Shift the name+value pairs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) memmove((char *)xh + first_namevalue_offset + namevalue_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) (char *)xh + first_namevalue_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) namevalue_offset - first_namevalue_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) memset((char *)xh + first_namevalue_offset, 0, namevalue_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) /* Now tell xh->xh_entries about it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) if (offset <= namevalue_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) le16_add_cpu(&xh->xh_entries[i].xe_name_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) namevalue_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) * Note that we don't update xh_free_start or xh_name_value_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) * because they're not used in block-stored xattrs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) static void ocfs2_xa_block_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) int count = le16_to_cpu(loc->xl_header->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) loc->xl_entry = &(loc->xl_header->xh_entries[count]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) le16_add_cpu(&loc->xl_header->xh_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) memset(loc->xl_entry, 0, sizeof(struct ocfs2_xattr_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) static void ocfs2_xa_block_add_namevalue(struct ocfs2_xa_loc *loc, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) int free_start = ocfs2_xa_get_free_start(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) loc->xl_entry->xe_name_offset = cpu_to_le16(free_start - size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) static void ocfs2_xa_block_fill_value_buf(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) struct ocfs2_xattr_value_buf *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) struct buffer_head *bh = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) if (loc->xl_size == (bh->b_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) offsetof(struct ocfs2_xattr_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) xb_attrs.xb_header)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) vb->vb_access = ocfs2_journal_access_xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) vb->vb_access = ocfs2_journal_access_di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) vb->vb_bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) * Operations for xattrs stored in blocks. This includes inline inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) * storage and unindexed ocfs2_xattr_blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) static const struct ocfs2_xa_loc_operations ocfs2_xa_block_loc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) .xlo_journal_access = ocfs2_xa_block_journal_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) .xlo_journal_dirty = ocfs2_xa_block_journal_dirty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) .xlo_offset_pointer = ocfs2_xa_block_offset_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) .xlo_check_space = ocfs2_xa_block_check_space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) .xlo_can_reuse = ocfs2_xa_block_can_reuse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) .xlo_get_free_start = ocfs2_xa_block_get_free_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) .xlo_wipe_namevalue = ocfs2_xa_block_wipe_namevalue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) .xlo_add_entry = ocfs2_xa_block_add_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) .xlo_add_namevalue = ocfs2_xa_block_add_namevalue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) .xlo_fill_value_buf = ocfs2_xa_block_fill_value_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) static int ocfs2_xa_bucket_journal_access(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) struct ocfs2_xa_loc *loc, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) struct ocfs2_xattr_bucket *bucket = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) return ocfs2_xattr_bucket_journal_access(handle, bucket, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) static void ocfs2_xa_bucket_journal_dirty(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) struct ocfs2_xattr_bucket *bucket = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) ocfs2_xattr_bucket_journal_dirty(handle, bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) static void *ocfs2_xa_bucket_offset_pointer(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct ocfs2_xattr_bucket *bucket = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) int block, block_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) /* The header is at the front of the bucket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) block = offset >> loc->xl_inode->i_sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) block_offset = offset % loc->xl_inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) return bucket_block(bucket, block) + block_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) static int ocfs2_xa_bucket_can_reuse(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) return namevalue_size_xe(loc->xl_entry) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) namevalue_size_xi(xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) static int ocfs2_xa_bucket_get_free_start(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) struct ocfs2_xattr_bucket *bucket = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) return le16_to_cpu(bucket_xh(bucket)->xh_free_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) static int ocfs2_bucket_align_free_start(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) int free_start, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) * We need to make sure that the name+value pair fits within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) * one block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) if (((free_start - size) >> sb->s_blocksize_bits) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) ((free_start - 1) >> sb->s_blocksize_bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) free_start -= free_start % sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) return free_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) static int ocfs2_xa_bucket_check_space(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) struct ocfs2_xattr_info *xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) int count = le16_to_cpu(loc->xl_header->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) int free_start = ocfs2_xa_get_free_start(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) int needed_space = ocfs2_xi_entry_usage(xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) int size = namevalue_size_xi(xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) struct super_block *sb = loc->xl_inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) * Bucket storage does not reclaim name+value pairs it cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) * reuse. They live as holes until the bucket fills, and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) * the bucket is defragmented. However, the bucket can reclaim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) * the ocfs2_xattr_entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) if (loc->xl_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) /* Don't need space if we're reusing! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) if (ocfs2_xa_can_reuse_entry(loc, xi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) needed_space = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) needed_space -= sizeof(struct ocfs2_xattr_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) BUG_ON(needed_space < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) if (free_start < size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) if (needed_space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) * First we check if it would fit in the first place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) * Below, we align the free start to a block. This may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) * slide us below the minimum gap. By checking unaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) * first, we avoid that error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) rc = ocfs2_xa_check_space_helper(needed_space, free_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) free_start = ocfs2_bucket_align_free_start(sb, free_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) return ocfs2_xa_check_space_helper(needed_space, free_start, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) static void ocfs2_xa_bucket_wipe_namevalue(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) le16_add_cpu(&loc->xl_header->xh_name_value_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) -namevalue_size_xe(loc->xl_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) static void ocfs2_xa_bucket_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) struct ocfs2_xattr_header *xh = loc->xl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) int count = le16_to_cpu(xh->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) int low = 0, high = count - 1, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) struct ocfs2_xattr_entry *tmp_xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) * We keep buckets sorted by name_hash, so we need to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) * our insert place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) while (low <= high && count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) tmp = (low + high) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) tmp_xe = &xh->xh_entries[tmp];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) if (name_hash > le32_to_cpu(tmp_xe->xe_name_hash))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) low = tmp + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) else if (name_hash < le32_to_cpu(tmp_xe->xe_name_hash))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) high = tmp - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) low = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) if (low != count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) memmove(&xh->xh_entries[low + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) &xh->xh_entries[low],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) ((count - low) * sizeof(struct ocfs2_xattr_entry)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) le16_add_cpu(&xh->xh_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) loc->xl_entry = &xh->xh_entries[low];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) memset(loc->xl_entry, 0, sizeof(struct ocfs2_xattr_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) static void ocfs2_xa_bucket_add_namevalue(struct ocfs2_xa_loc *loc, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) int free_start = ocfs2_xa_get_free_start(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) struct ocfs2_xattr_header *xh = loc->xl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) struct super_block *sb = loc->xl_inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) int nameval_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) free_start = ocfs2_bucket_align_free_start(sb, free_start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) nameval_offset = free_start - size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) loc->xl_entry->xe_name_offset = cpu_to_le16(nameval_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) xh->xh_free_start = cpu_to_le16(nameval_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) le16_add_cpu(&xh->xh_name_value_len, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) static void ocfs2_xa_bucket_fill_value_buf(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) struct ocfs2_xattr_value_buf *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) struct ocfs2_xattr_bucket *bucket = loc->xl_storage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) struct super_block *sb = loc->xl_inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) int size = namevalue_size_xe(loc->xl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) int block_offset = nameval_offset >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) /* Values are not allowed to straddle block boundaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) BUG_ON(block_offset !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) ((nameval_offset + size - 1) >> sb->s_blocksize_bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) /* We expect the bucket to be filled in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) BUG_ON(!bucket->bu_bhs[block_offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) vb->vb_access = ocfs2_journal_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) vb->vb_bh = bucket->bu_bhs[block_offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) /* Operations for xattrs stored in buckets. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) static const struct ocfs2_xa_loc_operations ocfs2_xa_bucket_loc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) .xlo_journal_access = ocfs2_xa_bucket_journal_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) .xlo_journal_dirty = ocfs2_xa_bucket_journal_dirty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) .xlo_offset_pointer = ocfs2_xa_bucket_offset_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) .xlo_check_space = ocfs2_xa_bucket_check_space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) .xlo_can_reuse = ocfs2_xa_bucket_can_reuse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) .xlo_get_free_start = ocfs2_xa_bucket_get_free_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) .xlo_wipe_namevalue = ocfs2_xa_bucket_wipe_namevalue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) .xlo_add_entry = ocfs2_xa_bucket_add_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) .xlo_add_namevalue = ocfs2_xa_bucket_add_namevalue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) .xlo_fill_value_buf = ocfs2_xa_bucket_fill_value_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) static unsigned int ocfs2_xa_value_clusters(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) struct ocfs2_xattr_value_buf vb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) if (ocfs2_xattr_is_local(loc->xl_entry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) ocfs2_xa_fill_value_buf(loc, &vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) return le32_to_cpu(vb.vb_xv->xr_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) static int ocfs2_xa_value_truncate(struct ocfs2_xa_loc *loc, u64 bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) int trunc_rc, access_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) struct ocfs2_xattr_value_buf vb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) ocfs2_xa_fill_value_buf(loc, &vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) trunc_rc = ocfs2_xattr_value_truncate(loc->xl_inode, &vb, bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) * The caller of ocfs2_xa_value_truncate() has already called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) * ocfs2_xa_journal_access on the loc. However, The truncate code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) * calls ocfs2_extend_trans(). This may commit the previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) * transaction and open a new one. If this is a bucket, truncate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) * could leave only vb->vb_bh set up for journaling. Meanwhile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) * the caller is expecting to dirty the entire bucket. So we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) * reset the journal work. We do this even if truncate has failed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) * as it could have failed after committing the extend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) access_rc = ocfs2_xa_journal_access(ctxt->handle, loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) /* Errors in truncate take precedence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) return trunc_rc ? trunc_rc : access_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) static void ocfs2_xa_remove_entry(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) int index, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) struct ocfs2_xattr_header *xh = loc->xl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) struct ocfs2_xattr_entry *entry = loc->xl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) ocfs2_xa_wipe_namevalue(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) loc->xl_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) le16_add_cpu(&xh->xh_count, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) count = le16_to_cpu(xh->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) * Only zero out the entry if there are more remaining. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) * important for an empty bucket, as it keeps track of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) * bucket's hash value. It doesn't hurt empty block storage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) index = ((char *)entry - (char *)&xh->xh_entries) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) sizeof(struct ocfs2_xattr_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) memmove(&xh->xh_entries[index], &xh->xh_entries[index + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) (count - index) * sizeof(struct ocfs2_xattr_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) memset(&xh->xh_entries[count], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) sizeof(struct ocfs2_xattr_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) * If we have a problem adjusting the size of an external value during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) * ocfs2_xa_prepare_entry() or ocfs2_xa_remove(), we may have an xattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) * in an intermediate state. For example, the value may be partially
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) * truncated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) * If the value tree hasn't changed, the extend/truncate went nowhere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) * We have nothing to do. The caller can treat it as a straight error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) * If the value tree got partially truncated, we now have a corrupted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) * extended attribute. We're going to wipe its entry and leak the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) * clusters. Better to leak some storage than leave a corrupt entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) * If the value tree grew, it obviously didn't grow enough for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) * new entry. We're not going to try and reclaim those clusters either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) * If there was already an external value there (orig_clusters != 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) * the new clusters are attached safely and we can just leave the old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) * value in place. If there was no external value there, we remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) * the entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) * This way, the xattr block we store in the journal will be consistent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) * If the size change broke because of the journal, no changes will hit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) * disk anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) static void ocfs2_xa_cleanup_value_truncate(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) const char *what,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) unsigned int orig_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) unsigned int new_clusters = ocfs2_xa_value_clusters(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) char *nameval_buf = ocfs2_xa_offset_pointer(loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) le16_to_cpu(loc->xl_entry->xe_name_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) if (new_clusters < orig_clusters) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) mlog(ML_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) "Partial truncate while %s xattr %.*s. Leaking "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) "%u clusters and removing the entry\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) what, loc->xl_entry->xe_name_len, nameval_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) orig_clusters - new_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) ocfs2_xa_remove_entry(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) } else if (!orig_clusters) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) mlog(ML_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) "Unable to allocate an external value for xattr "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) "%.*s safely. Leaking %u clusters and removing the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) "entry\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) loc->xl_entry->xe_name_len, nameval_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) new_clusters - orig_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) ocfs2_xa_remove_entry(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) } else if (new_clusters > orig_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) mlog(ML_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) "Unable to grow xattr %.*s safely. %u new clusters "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) "have been added, but the value will not be "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) "modified\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) loc->xl_entry->xe_name_len, nameval_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) new_clusters - orig_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) static int ocfs2_xa_remove(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) unsigned int orig_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) if (!ocfs2_xattr_is_local(loc->xl_entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) orig_clusters = ocfs2_xa_value_clusters(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) * Since this is remove, we can return 0 if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) * ocfs2_xa_cleanup_value_truncate() is going to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) * wipe the entry anyway. So we check the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) * cluster count as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) if (orig_clusters != ocfs2_xa_value_clusters(loc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) ocfs2_xa_cleanup_value_truncate(loc, "removing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) orig_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) ocfs2_xa_remove_entry(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) static void ocfs2_xa_install_value_root(struct ocfs2_xa_loc *loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) int name_size = OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) char *nameval_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) nameval_buf = ocfs2_xa_offset_pointer(loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) le16_to_cpu(loc->xl_entry->xe_name_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) memcpy(nameval_buf + name_size, &def_xv, OCFS2_XATTR_ROOT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) * Take an existing entry and make it ready for the new value. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) * won't allocate space, but it may free space. It should be ready for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) * ocfs2_xa_prepare_entry() to finish the work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) static int ocfs2_xa_reuse_entry(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) int name_size = OCFS2_XATTR_SIZE(xi->xi_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) unsigned int orig_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) char *nameval_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) int xe_local = ocfs2_xattr_is_local(loc->xl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) int xi_local = xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) BUG_ON(OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) nameval_buf = ocfs2_xa_offset_pointer(loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) le16_to_cpu(loc->xl_entry->xe_name_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) if (xe_local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) memset(nameval_buf + name_size, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) namevalue_size_xe(loc->xl_entry) - name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (!xi_local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) ocfs2_xa_install_value_root(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) orig_clusters = ocfs2_xa_value_clusters(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) if (xi_local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) memset(nameval_buf + name_size, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) namevalue_size_xe(loc->xl_entry) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) } else if (le64_to_cpu(loc->xl_entry->xe_value_size) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) xi->xi_value_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) rc = ocfs2_xa_value_truncate(loc, xi->xi_value_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) ocfs2_xa_cleanup_value_truncate(loc, "reusing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) orig_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) ocfs2_xattr_set_local(loc->xl_entry, xi_local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) * Prepares loc->xl_entry to receive the new xattr. This includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) * properly setting up the name+value pair region. If loc->xl_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) * already exists, it will take care of modifying it appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) * Note that this modifies the data. You did journal_access already,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) * right?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) u32 name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) unsigned int orig_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) __le64 orig_value_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) rc = ocfs2_xa_check_space(loc, xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) if (loc->xl_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) if (ocfs2_xa_can_reuse_entry(loc, xi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) orig_value_size = loc->xl_entry->xe_value_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) goto alloc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) if (!ocfs2_xattr_is_local(loc->xl_entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) orig_clusters = ocfs2_xa_value_clusters(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) ocfs2_xa_cleanup_value_truncate(loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) "overwriting",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) orig_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) ocfs2_xa_wipe_namevalue(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) ocfs2_xa_add_entry(loc, name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) * If we get here, we have a blank entry. Fill it. We grow our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) * name+value pair back from the end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) ocfs2_xa_add_namevalue(loc, xi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) ocfs2_xa_install_value_root(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) alloc_value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) orig_clusters = ocfs2_xa_value_clusters(loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) rc = ocfs2_xa_value_truncate(loc, xi->xi_value_len, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) ctxt->set_abort = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) ocfs2_xa_cleanup_value_truncate(loc, "growing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) orig_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) * If we were growing an existing value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) * ocfs2_xa_cleanup_value_truncate() won't remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) * the entry. We need to restore the original value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) * size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) if (loc->xl_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) BUG_ON(!orig_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) loc->xl_entry->xe_value_size = orig_value_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) mlog_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) * Store the value portion of the name+value pair. This will skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) * values that are stored externally. Their tree roots were set up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) * by ocfs2_xa_prepare_entry().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) static int ocfs2_xa_store_value(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) int name_size = OCFS2_XATTR_SIZE(xi->xi_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) char *nameval_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) struct ocfs2_xattr_value_buf vb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) nameval_buf = ocfs2_xa_offset_pointer(loc, nameval_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) ocfs2_xa_fill_value_buf(loc, &vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) rc = __ocfs2_xattr_set_value_outside(loc->xl_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) ctxt->handle, &vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) xi->xi_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) xi->xi_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) memcpy(nameval_buf + name_size, xi->xi_value, xi->xi_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) static int ocfs2_xa_set(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) u32 name_hash = ocfs2_xattr_name_hash(loc->xl_inode, xi->xi_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) xi->xi_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) ret = ocfs2_xa_journal_access(ctxt->handle, loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) * From here on out, everything is going to modify the buffer a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) * little. Errors are going to leave the xattr header in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) * sane state. Thus, even with errors we dirty the sucker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) /* Don't worry, we are never called with !xi_value and !xl_entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) if (!xi->xi_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) ret = ocfs2_xa_remove(loc, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) goto out_dirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) ret = ocfs2_xa_prepare_entry(loc, xi, name_hash, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) if (ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) goto out_dirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) ret = ocfs2_xa_store_value(loc, xi, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) out_dirty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) ocfs2_xa_journal_dirty(ctxt->handle, loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) static void ocfs2_init_dinode_xa_loc(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) struct ocfs2_xattr_entry *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_XATTR_FL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) loc->xl_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) loc->xl_ops = &ocfs2_xa_block_loc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) loc->xl_storage = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) loc->xl_entry = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) loc->xl_size = le16_to_cpu(di->i_xattr_inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) loc->xl_header =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) (struct ocfs2_xattr_header *)(bh->b_data + bh->b_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) loc->xl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) static void ocfs2_init_xattr_block_xa_loc(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) struct ocfs2_xattr_entry *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) (struct ocfs2_xattr_block *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) BUG_ON(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) loc->xl_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) loc->xl_ops = &ocfs2_xa_block_loc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) loc->xl_storage = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) loc->xl_header = &(xb->xb_attrs.xb_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) loc->xl_entry = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) loc->xl_size = bh->b_size - offsetof(struct ocfs2_xattr_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) xb_attrs.xb_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) static void ocfs2_init_xattr_bucket_xa_loc(struct ocfs2_xa_loc *loc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) struct ocfs2_xattr_entry *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) loc->xl_inode = bucket->bu_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) loc->xl_ops = &ocfs2_xa_bucket_loc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) loc->xl_storage = bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) loc->xl_header = bucket_xh(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) loc->xl_entry = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) loc->xl_size = OCFS2_XATTR_BUCKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) * In xattr remove, if it is stored outside and refcounted, we may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) * the chance to split the refcount tree. So need the allocators.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) static int ocfs2_lock_xattr_remove_allocators(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) struct ocfs2_xattr_value_root *xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) struct buffer_head *ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) struct ocfs2_alloc_context **meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) int *ref_credits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) int ret, meta_add = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) u32 p_cluster, num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) unsigned int ext_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) *ref_credits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) ret = ocfs2_xattr_get_clusters(inode, 0, &p_cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) &num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) &xv->xr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) &ext_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) if (!(ext_flags & OCFS2_EXT_REFCOUNTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) ret = ocfs2_refcounted_xattr_delete_need(inode, ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) ref_root_bh, xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) &meta_add, ref_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) ret = ocfs2_reserve_new_metadata_blocks(OCFS2_SB(inode->i_sb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) meta_add, meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) static int ocfs2_remove_value_outside(struct inode*inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) struct ocfs2_xattr_header *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) struct buffer_head *ref_root_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) int ret = 0, i, ref_credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) struct ocfs2_xattr_set_ctxt ctxt = { NULL, NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) void *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) ocfs2_init_dealloc_ctxt(&ctxt.dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) for (i = 0; i < le16_to_cpu(header->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) struct ocfs2_xattr_entry *entry = &header->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) if (ocfs2_xattr_is_local(entry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) val = (void *)header +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) le16_to_cpu(entry->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) vb->vb_xv = (struct ocfs2_xattr_value_root *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) (val + OCFS2_XATTR_SIZE(entry->xe_name_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) ret = ocfs2_lock_xattr_remove_allocators(inode, vb->vb_xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) ref_ci, ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) &ctxt.meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) &ref_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) ctxt.handle = ocfs2_start_trans(osb, ref_credits +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) ocfs2_remove_extent_credits(osb->sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) if (IS_ERR(ctxt.handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) ret = PTR_ERR(ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) ret = ocfs2_xattr_value_truncate(inode, vb, 0, &ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) ocfs2_commit_trans(osb, ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) if (ctxt.meta_ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) ocfs2_free_alloc_context(ctxt.meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) ctxt.meta_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) if (ctxt.meta_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) ocfs2_free_alloc_context(ctxt.meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) ocfs2_schedule_truncate_log_flush(osb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) ocfs2_run_deallocs(osb, &ctxt.dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) static int ocfs2_xattr_ibody_remove(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) struct buffer_head *di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) struct buffer_head *ref_root_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) struct ocfs2_xattr_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) .vb_bh = di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) .vb_access = ocfs2_journal_access_di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) header = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) ((void *)di + inode->i_sb->s_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) le16_to_cpu(di->i_xattr_inline_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) ret = ocfs2_remove_value_outside(inode, &vb, header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) ref_ci, ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) struct ocfs2_rm_xattr_bucket_para {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) struct ocfs2_caching_info *ref_ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) struct buffer_head *ref_root_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) static int ocfs2_xattr_block_remove(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) struct buffer_head *blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) struct buffer_head *ref_root_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) struct ocfs2_xattr_block *xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) .vb_bh = blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) .vb_access = ocfs2_journal_access_xb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) struct ocfs2_rm_xattr_bucket_para args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) .ref_ci = ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) .ref_root_bh = ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) struct ocfs2_xattr_header *header = &(xb->xb_attrs.xb_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) ret = ocfs2_remove_value_outside(inode, &vb, header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) ref_ci, ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) ret = ocfs2_iterate_xattr_index_block(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) ocfs2_rm_xattr_cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) static int ocfs2_xattr_free_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) u64 block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) struct buffer_head *ref_root_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) struct inode *xb_alloc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) struct buffer_head *xb_alloc_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) struct buffer_head *blk_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) struct ocfs2_xattr_block *xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) u64 blk, bg_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) u16 bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) ret = ocfs2_read_xattr_block(inode, block, &blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) ret = ocfs2_xattr_block_remove(inode, blk_bh, ref_ci, ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) blk = le64_to_cpu(xb->xb_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) bit = le16_to_cpu(xb->xb_suballoc_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) if (xb->xb_suballoc_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) bg_blkno = le64_to_cpu(xb->xb_suballoc_loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) bg_blkno = ocfs2_which_suballoc_group(blk, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) xb_alloc_inode = ocfs2_get_system_file_inode(osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) EXTENT_ALLOC_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) le16_to_cpu(xb->xb_suballoc_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) if (!xb_alloc_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) inode_lock(xb_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) ret = ocfs2_inode_lock(xb_alloc_inode, &xb_alloc_bh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) goto out_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) handle = ocfs2_start_trans(osb, OCFS2_SUBALLOC_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) ret = ocfs2_free_suballoc_bits(handle, xb_alloc_inode, xb_alloc_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) bit, bg_blkno, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) ocfs2_inode_unlock(xb_alloc_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) brelse(xb_alloc_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) out_mutex:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) inode_unlock(xb_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) iput(xb_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) brelse(blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) * ocfs2_xattr_remove()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) * Free extended attribute resources associated with this inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) struct ocfs2_refcount_tree *ref_tree = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) struct buffer_head *ref_root_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) struct ocfs2_caching_info *ref_ci = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) if (ocfs2_is_refcount_inode(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) ret = ocfs2_lock_refcount_tree(OCFS2_SB(inode->i_sb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) le64_to_cpu(di->i_refcount_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 1, &ref_tree, &ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) ref_ci = &ref_tree->rf_ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) ret = ocfs2_xattr_ibody_remove(inode, di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) ref_ci, ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) if (di->i_xattr_loc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) ret = ocfs2_xattr_free_block(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) le64_to_cpu(di->i_xattr_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) ref_ci, ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) OCFS2_INODE_UPDATE_CREDITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) di->i_xattr_loc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) spin_lock(&oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) oi->ip_dyn_features &= ~(OCFS2_INLINE_XATTR_FL | OCFS2_HAS_XATTR_FL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) spin_unlock(&oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) ocfs2_update_inode_fsync_trans(handle, inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) ocfs2_journal_dirty(handle, di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) out_commit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) if (ref_tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) ocfs2_unlock_refcount_tree(OCFS2_SB(inode->i_sb), ref_tree, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) brelse(ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) static int ocfs2_xattr_has_space_inline(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) struct ocfs2_dinode *di)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) unsigned int xattrsize = OCFS2_SB(inode->i_sb)->s_xattr_inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) int free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) if (xattrsize < OCFS2_MIN_XATTR_INLINE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) struct ocfs2_inline_data *idata = &di->id2.i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) free = le16_to_cpu(idata->id_count) - le64_to_cpu(di->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) } else if (ocfs2_inode_is_fast_symlink(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) free = ocfs2_fast_symlink_chars(inode->i_sb) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) le64_to_cpu(di->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) struct ocfs2_extent_list *el = &di->id2.i_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) free = (le16_to_cpu(el->l_count) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) le16_to_cpu(el->l_next_free_rec)) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) sizeof(struct ocfs2_extent_rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) if (free >= xattrsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) * ocfs2_xattr_ibody_find()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) * Find extended attribute in inode block and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) * fill search info into struct ocfs2_xattr_search.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) static int ocfs2_xattr_ibody_find(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) int has_space = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) down_read(&oi->ip_alloc_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) has_space = ocfs2_xattr_has_space_inline(inode, di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) up_read(&oi->ip_alloc_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) if (!has_space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) xs->xattr_bh = xs->inode_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) xs->end = (void *)di + inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) xs->header = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) (xs->end - le16_to_cpu(di->i_xattr_inline_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) xs->header = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) (xs->end - OCFS2_SB(inode->i_sb)->s_xattr_inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) xs->base = (void *)xs->header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) xs->here = xs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) /* Find the named attribute. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) ret = ocfs2_xattr_find_entry(name_index, name, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) if (ret && ret != -ENODATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) xs->not_found = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) static int ocfs2_xattr_ibody_init(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) struct buffer_head *di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) unsigned int xattrsize = osb->s_xattr_inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) if (!ocfs2_xattr_has_space_inline(inode, di)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode), di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) * Adjust extent record count or inline data size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) * to reserve space for extended attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) struct ocfs2_inline_data *idata = &di->id2.i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) le16_add_cpu(&idata->id_count, -xattrsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) } else if (!(ocfs2_inode_is_fast_symlink(inode))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) struct ocfs2_extent_list *el = &di->id2.i_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) le16_add_cpu(&el->l_count, -(xattrsize /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) sizeof(struct ocfs2_extent_rec)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) di->i_xattr_inline_size = cpu_to_le16(xattrsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) spin_lock(&oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) oi->ip_dyn_features |= OCFS2_INLINE_XATTR_FL|OCFS2_HAS_XATTR_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) spin_unlock(&oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) ocfs2_journal_dirty(ctxt->handle, di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) * ocfs2_xattr_ibody_set()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) * Set, replace or remove an extended attribute into inode block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) static int ocfs2_xattr_ibody_set(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) struct ocfs2_xa_loc loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) down_write(&oi->ip_alloc_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) ret = ocfs2_xattr_ibody_init(inode, xs->inode_bh, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) if (ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) ocfs2_init_dinode_xa_loc(&loc, inode, xs->inode_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) xs->not_found ? NULL : xs->here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) ret = ocfs2_xa_set(&loc, xi, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) if (ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) xs->here = loc.xl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) up_write(&oi->ip_alloc_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) * ocfs2_xattr_block_find()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) * Find extended attribute in external block and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) * fill search info into struct ocfs2_xattr_search.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) static int ocfs2_xattr_block_find(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) struct buffer_head *blk_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) struct ocfs2_xattr_block *xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) if (!di->i_xattr_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) ret = ocfs2_read_xattr_block(inode, le64_to_cpu(di->i_xattr_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) &blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) xs->xattr_bh = blk_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) xs->header = &xb->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) xs->base = (void *)xs->header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) xs->end = (void *)(blk_bh->b_data) + blk_bh->b_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) xs->here = xs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) ret = ocfs2_xattr_find_entry(name_index, name, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) ret = ocfs2_xattr_index_block_find(inode, blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) name, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) if (ret && ret != -ENODATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) xs->xattr_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) xs->not_found = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) brelse(blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) static int ocfs2_create_xattr_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) struct buffer_head *inode_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) struct ocfs2_xattr_set_ctxt *ctxt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) int indexed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) struct buffer_head **ret_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) u16 suballoc_bit_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) u32 num_got;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) u64 suballoc_loc, first_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) struct ocfs2_dinode *di = (struct ocfs2_dinode *)inode_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) struct buffer_head *new_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) struct ocfs2_xattr_block *xblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) inode_bh, OCFS2_JOURNAL_ACCESS_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) ret = ocfs2_claim_metadata(ctxt->handle, ctxt->meta_ac, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) &suballoc_loc, &suballoc_bit_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) &num_got, &first_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) new_bh = sb_getblk(inode->i_sb, first_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) if (!new_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) ret = ocfs2_journal_access_xb(ctxt->handle, INODE_CACHE(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) new_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) OCFS2_JOURNAL_ACCESS_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) /* Initialize ocfs2_xattr_block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) xblk = (struct ocfs2_xattr_block *)new_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) memset(xblk, 0, inode->i_sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) xblk->xb_suballoc_slot = cpu_to_le16(ctxt->meta_ac->ac_alloc_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) xblk->xb_suballoc_loc = cpu_to_le64(suballoc_loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) xblk->xb_fs_generation =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) cpu_to_le32(OCFS2_SB(inode->i_sb)->fs_generation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) xblk->xb_blkno = cpu_to_le64(first_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) if (indexed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) struct ocfs2_xattr_tree_root *xr = &xblk->xb_attrs.xb_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) xr->xt_clusters = cpu_to_le32(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) xr->xt_last_eb_blk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) xr->xt_list.l_tree_depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) xr->xt_list.l_count = cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) ocfs2_xattr_recs_per_xb(inode->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) xr->xt_list.l_next_free_rec = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) xblk->xb_flags = cpu_to_le16(OCFS2_XATTR_INDEXED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) ocfs2_journal_dirty(ctxt->handle, new_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) /* Add it to the inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) di->i_xattr_loc = cpu_to_le64(first_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) spin_lock(&OCFS2_I(inode)->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) OCFS2_I(inode)->ip_dyn_features |= OCFS2_HAS_XATTR_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) di->i_dyn_features = cpu_to_le16(OCFS2_I(inode)->ip_dyn_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) spin_unlock(&OCFS2_I(inode)->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) ocfs2_journal_dirty(ctxt->handle, inode_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) *ret_bh = new_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) new_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) brelse(new_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) * ocfs2_xattr_block_set()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) * Set, replace or remove an extended attribute into external block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) static int ocfs2_xattr_block_set(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) struct buffer_head *new_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) struct ocfs2_xattr_block *xblk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) struct ocfs2_xa_loc loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) if (!xs->xattr_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) ret = ocfs2_create_xattr_block(inode, xs->inode_bh, ctxt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 0, &new_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) xs->xattr_bh = new_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) xs->header = &xblk->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) xs->base = (void *)xs->header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) xs->end = (void *)xblk + inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) xs->here = xs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) if (!(le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) ocfs2_init_xattr_block_xa_loc(&loc, inode, xs->xattr_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) xs->not_found ? NULL : xs->here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) ret = ocfs2_xa_set(&loc, xi, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) xs->here = loc.xl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) else if ((ret != -ENOSPC) || ctxt->set_abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) ret = ocfs2_xattr_create_index_block(inode, xs, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) if (le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) ret = ocfs2_xattr_set_entry_index_block(inode, xi, xs, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) /* Check whether the new xattr can be inserted into the inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) static int ocfs2_xattr_can_be_in_inode(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) struct ocfs2_xattr_entry *last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) int free, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) size_t min_offs = xs->end - xs->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) if (!xs->header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) last = xs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) for (i = 0; i < le16_to_cpu(xs->header->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) size_t offs = le16_to_cpu(last->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) if (offs < min_offs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) min_offs = offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) last += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) free = min_offs - ((void *)last - xs->base) - OCFS2_XATTR_HEADER_GAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) if (free < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) BUG_ON(!xs->not_found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) if (free >= (sizeof(struct ocfs2_xattr_entry) + namevalue_size_xi(xi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) static int ocfs2_calc_xattr_set_need(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) struct ocfs2_dinode *di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) struct ocfs2_xattr_search *xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) struct ocfs2_xattr_search *xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) int *clusters_need,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) int *meta_need,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) int *credits_need)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) int ret = 0, old_in_xb = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) int clusters_add = 0, meta_add = 0, credits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) struct ocfs2_xattr_block *xb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) struct ocfs2_xattr_entry *xe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) struct ocfs2_xattr_value_root *xv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) char *base = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) int name_offset, name_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) u32 new_clusters = ocfs2_clusters_for_bytes(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) xi->xi_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) u64 value_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) * Calculate the clusters we need to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) * No matter whether we replace an old one or add a new one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) * we need this for writing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) credits += new_clusters *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) ocfs2_clusters_to_blocks(inode->i_sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) if (xis->not_found && xbs->not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) clusters_add += new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) credits += ocfs2_calc_extend_credits(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) &def_xv.xv.xr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) goto meta_guess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) if (!xis->not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) xe = xis->here;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) name_offset = le16_to_cpu(xe->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) name_len = OCFS2_XATTR_SIZE(xe->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) base = xis->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) credits += OCFS2_INODE_UPDATE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) int i, block_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) xb = (struct ocfs2_xattr_block *)xbs->xattr_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) xe = xbs->here;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) name_offset = le16_to_cpu(xe->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) name_len = OCFS2_XATTR_SIZE(xe->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) i = xbs->here - xbs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) old_in_xb = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) bucket_xh(xbs->bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) i, &block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) &name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) base = bucket_block(xbs->bucket, block_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) base = xbs->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) credits += OCFS2_XATTR_BLOCK_UPDATE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) * delete a xattr doesn't need metadata and cluster allocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) * so just calculate the credits and return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) * The credits for removing the value tree will be extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) * by ocfs2_remove_extent itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) if (!xi->xi_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) if (!ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) credits += ocfs2_remove_extent_credits(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) /* do cluster allocation guess first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) value_size = le64_to_cpu(xe->xe_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) if (old_in_xb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) * In xattr set, we always try to set the xe in inode first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) * so if it can be inserted into inode successfully, the old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) * one will be removed from the xattr block, and this xattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) * will be inserted into inode as a new xattr in inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) if (ocfs2_xattr_can_be_in_inode(inode, xi, xis)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) clusters_add += new_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) credits += ocfs2_remove_extent_credits(inode->i_sb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) OCFS2_INODE_UPDATE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) if (!ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) credits += ocfs2_calc_extend_credits(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) &def_xv.xv.xr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) /* the new values will be stored outside. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) u32 old_clusters = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) if (!ocfs2_xattr_is_local(xe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) old_clusters = ocfs2_clusters_for_bytes(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) xv = (struct ocfs2_xattr_value_root *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) (base + name_offset + name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) value_size = OCFS2_XATTR_ROOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) xv = &def_xv.xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) if (old_clusters >= new_clusters) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) credits += ocfs2_remove_extent_credits(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) meta_add += ocfs2_extend_meta_needed(&xv->xr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) clusters_add += new_clusters - old_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) credits += ocfs2_calc_extend_credits(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) &xv->xr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) if (value_size >= OCFS2_XATTR_ROOT_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) * Now the new value will be stored inside. So if the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) * value is smaller than the size of value root or the old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) * value, we don't need any allocation, otherwise we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) * to guess metadata allocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) if ((ocfs2_xattr_is_local(xe) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) (value_size >= xi->xi_value_len)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) (!ocfs2_xattr_is_local(xe) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) OCFS2_XATTR_ROOT_SIZE >= xi->xi_value_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) meta_guess:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) /* calculate metadata allocation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) if (di->i_xattr_loc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) if (!xbs->xattr_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) ret = ocfs2_read_xattr_block(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) le64_to_cpu(di->i_xattr_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) xb = (struct ocfs2_xattr_block *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) xb = (struct ocfs2_xattr_block *)xbs->xattr_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) * If there is already an xattr tree, good, we can calculate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) * like other b-trees. Otherwise we may have the chance of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) * create a tree, the credit calculation is borrowed from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) * ocfs2_calc_extend_credits with root_el = NULL. And the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) * new tree will be cluster based, so no meta is needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) struct ocfs2_extent_list *el =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) &xb->xb_attrs.xb_root.xt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) meta_add += ocfs2_extend_meta_needed(el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) credits += ocfs2_calc_extend_credits(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) credits += OCFS2_SUBALLOC_ALLOC + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) * This cluster will be used either for new bucket or for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) * new xattr block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) * If the cluster size is the same as the bucket size, one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) * more is needed since we may need to extend the bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) * also.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) clusters_add += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) if (OCFS2_XATTR_BUCKET_SIZE ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) OCFS2_SB(inode->i_sb)->s_clustersize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) clusters_add += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) struct ocfs2_extent_list *el = &def_xv.xv.xr_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) meta_add += ocfs2_extend_meta_needed(el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) credits += ocfs2_calc_extend_credits(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) meta_add += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) if (clusters_need)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) *clusters_need = clusters_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) if (meta_need)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) *meta_need = meta_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) if (credits_need)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) *credits_need = credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) static int ocfs2_init_xattr_set_ctxt(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) struct ocfs2_dinode *di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) struct ocfs2_xattr_search *xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) struct ocfs2_xattr_search *xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) struct ocfs2_xattr_set_ctxt *ctxt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) int extra_meta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) int *credits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) int clusters_add, meta_add, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) memset(ctxt, 0, sizeof(struct ocfs2_xattr_set_ctxt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) ocfs2_init_dealloc_ctxt(&ctxt->dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) ret = ocfs2_calc_xattr_set_need(inode, di, xi, xis, xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) &clusters_add, &meta_add, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) meta_add += extra_meta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) trace_ocfs2_init_xattr_set_ctxt(xi->xi_name, meta_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) clusters_add, *credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) if (meta_add) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) &ctxt->meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) if (clusters_add) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) ret = ocfs2_reserve_clusters(osb, clusters_add, &ctxt->data_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) if (ctxt->meta_ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) ocfs2_free_alloc_context(ctxt->meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) ctxt->meta_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) * We cannot have an error and a non null ctxt->data_ac.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) static int __ocfs2_xattr_set_handle(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) struct ocfs2_dinode *di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) struct ocfs2_xattr_search *xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) struct ocfs2_xattr_search *xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) int ret = 0, credits, old_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) if (!xi->xi_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) /* Remove existing extended attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) if (!xis->not_found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) ret = ocfs2_xattr_ibody_set(inode, xi, xis, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) else if (!xbs->not_found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) ret = ocfs2_xattr_block_set(inode, xi, xbs, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) /* We always try to set extended attribute into inode first*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) ret = ocfs2_xattr_ibody_set(inode, xi, xis, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) if (!ret && !xbs->not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) * If succeed and that extended attribute existing in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) * external block, then we will remove it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) xi->xi_value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) xi->xi_value_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) old_found = xis->not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) xis->not_found = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) ret = ocfs2_calc_xattr_set_need(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) &credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) xis->not_found = old_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) ret = ocfs2_extend_trans(ctxt->handle, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) ret = ocfs2_xattr_block_set(inode, xi, xbs, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) } else if ((ret == -ENOSPC) && !ctxt->set_abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) if (di->i_xattr_loc && !xbs->xattr_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) ret = ocfs2_xattr_block_find(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) xi->xi_name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) xi->xi_name, xbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) old_found = xis->not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) xis->not_found = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) ret = ocfs2_calc_xattr_set_need(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) &credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) xis->not_found = old_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) ret = ocfs2_extend_trans(ctxt->handle, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) * If no space in inode, we will set extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) * into external block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) ret = ocfs2_xattr_block_set(inode, xi, xbs, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) if (!xis->not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) * If succeed and that extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) * existing in inode, we will remove it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) xi->xi_value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) xi->xi_value_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) xbs->not_found = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) ret = ocfs2_calc_xattr_set_need(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) &credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) ret = ocfs2_extend_trans(ctxt->handle, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) ret = ocfs2_xattr_ibody_set(inode, xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) xis, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) /* Update inode ctime. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) xis->inode_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) di->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) di->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) ocfs2_journal_dirty(ctxt->handle, xis->inode_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) * This function only called duing creating inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) * for init security/acl xattrs of the new inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) * All transanction credits have been reserved in mknod.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) int ocfs2_xattr_set_handle(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) struct buffer_head *di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) size_t value_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) struct ocfs2_alloc_context *data_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) struct ocfs2_dinode *di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) struct ocfs2_xattr_info xi = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) .xi_name_index = name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) .xi_name = name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) .xi_name_len = strlen(name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) .xi_value = value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) .xi_value_len = value_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) struct ocfs2_xattr_search xis = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) .not_found = -ENODATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) struct ocfs2_xattr_search xbs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) .not_found = -ENODATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) struct ocfs2_xattr_set_ctxt ctxt = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) .handle = handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) .meta_ac = meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) .data_ac = data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) * In extreme situation, may need xattr bucket when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) * block size is too small. And we have already reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) * the credits for bucket in mknod.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) xbs.bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) if (!xbs.bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) mlog_errno(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) xis.inode_bh = xbs.inode_bh = di_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) di = (struct ocfs2_dinode *)di_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) down_write(&OCFS2_I(inode)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) ret = ocfs2_xattr_ibody_find(inode, name_index, name, &xis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) if (xis.not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) ret = ocfs2_xattr_block_find(inode, name_index, name, &xbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) ret = __ocfs2_xattr_set_handle(inode, di, &xi, &xis, &xbs, &ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) up_write(&OCFS2_I(inode)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) brelse(xbs.xattr_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) ocfs2_xattr_bucket_free(xbs.bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) * ocfs2_xattr_set()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) * Set, replace or remove an extended attribute for this inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) * value is NULL to remove an existing extended attribute, else either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) * create or replace an extended attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) int ocfs2_xattr_set(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) size_t value_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) struct buffer_head *di_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) struct ocfs2_dinode *di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) int ret, credits, had_lock, ref_meta = 0, ref_credits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) struct inode *tl_inode = osb->osb_tl_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) struct ocfs2_xattr_set_ctxt ctxt = { NULL, NULL, NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) struct ocfs2_refcount_tree *ref_tree = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) struct ocfs2_lock_holder oh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) struct ocfs2_xattr_info xi = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) .xi_name_index = name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) .xi_name = name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) .xi_name_len = strlen(name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) .xi_value = value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) .xi_value_len = value_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) struct ocfs2_xattr_search xis = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) .not_found = -ENODATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) struct ocfs2_xattr_search xbs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) .not_found = -ENODATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) if (!ocfs2_supports_xattr(osb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) * Only xbs will be used on indexed trees. xis doesn't need a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) * bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) xbs.bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) if (!xbs.bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) mlog_errno(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) had_lock = ocfs2_inode_lock_tracker(inode, &di_bh, 1, &oh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) if (had_lock < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) ret = had_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) goto cleanup_nolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) xis.inode_bh = xbs.inode_bh = di_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) di = (struct ocfs2_dinode *)di_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) down_write(&OCFS2_I(inode)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) * Scan inode and external block to find the same name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) * extended attribute and collect search information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) ret = ocfs2_xattr_ibody_find(inode, name_index, name, &xis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) if (xis.not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) ret = ocfs2_xattr_block_find(inode, name_index, name, &xbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) if (xis.not_found && xbs.not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) ret = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) if (flags & XATTR_REPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) ret = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) if (flags & XATTR_CREATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) /* Check whether the value is refcounted and do some preparation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) if (ocfs2_is_refcount_inode(inode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) (!xis.not_found || !xbs.not_found)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) ret = ocfs2_prepare_refcount_xattr(inode, di, &xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) &xis, &xbs, &ref_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) &ref_meta, &ref_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) inode_lock(tl_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) if (ocfs2_truncate_log_needs_flush(osb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) ret = __ocfs2_flush_truncate_log(osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) inode_unlock(tl_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) inode_unlock(tl_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) ret = ocfs2_init_xattr_set_ctxt(inode, di, &xi, &xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) &xbs, &ctxt, ref_meta, &credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) /* we need to update inode's ctime field, so add credit for it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) credits += OCFS2_INODE_UPDATE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) ctxt.handle = ocfs2_start_trans(osb, credits + ref_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) if (IS_ERR(ctxt.handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) ret = PTR_ERR(ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) goto out_free_ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) ret = __ocfs2_xattr_set_handle(inode, di, &xi, &xis, &xbs, &ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) ocfs2_update_inode_fsync_trans(ctxt.handle, inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) ocfs2_commit_trans(osb, ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) out_free_ac:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) if (ctxt.data_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) ocfs2_free_alloc_context(ctxt.data_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) if (ctxt.meta_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) ocfs2_free_alloc_context(ctxt.meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) if (ocfs2_dealloc_has_cluster(&ctxt.dealloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) ocfs2_schedule_truncate_log_flush(osb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) ocfs2_run_deallocs(osb, &ctxt.dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) if (ref_tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) ocfs2_unlock_refcount_tree(osb, ref_tree, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) up_write(&OCFS2_I(inode)->ip_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) if (!value && !ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) ret = ocfs2_try_remove_refcount_tree(inode, di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) ocfs2_inode_unlock_tracker(inode, 1, &oh, had_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) cleanup_nolock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) brelse(di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) brelse(xbs.xattr_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) ocfs2_xattr_bucket_free(xbs.bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) * Find the xattr extent rec which may contains name_hash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) * e_cpos will be the first name hash of the xattr rec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) * el must be the ocfs2_xattr_header.xb_attrs.xb_root.xt_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) static int ocfs2_xattr_get_rec(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) u32 name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) u64 *p_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) u32 *e_cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) u32 *num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) struct ocfs2_extent_list *el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) int ret = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) struct buffer_head *eb_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) struct ocfs2_extent_block *eb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) struct ocfs2_extent_rec *rec = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) u64 e_blkno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) if (el->l_tree_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) ret = ocfs2_find_leaf(INODE_CACHE(inode), el, name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) &eb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) eb = (struct ocfs2_extent_block *) eb_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) el = &eb->h_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) if (el->l_tree_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) ret = ocfs2_error(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) "Inode %lu has non zero tree depth in xattr tree block %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) (unsigned long long)eb_bh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) for (i = le16_to_cpu(el->l_next_free_rec) - 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) rec = &el->l_recs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) if (le32_to_cpu(rec->e_cpos) <= name_hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) e_blkno = le64_to_cpu(rec->e_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) if (!e_blkno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) ret = ocfs2_error(inode->i_sb, "Inode %lu has bad extent record (%u, %u, 0) in xattr\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) le32_to_cpu(rec->e_cpos),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) ocfs2_rec_clusters(el, rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) *p_blkno = le64_to_cpu(rec->e_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) *num_clusters = le16_to_cpu(rec->e_leaf_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) if (e_cpos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) *e_cpos = le32_to_cpu(rec->e_cpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) brelse(eb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) typedef int (xattr_bucket_func)(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) void *para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) static int ocfs2_find_xe_in_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) u32 name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) u16 *xe_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) int *found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) int i, ret = 0, cmp = 1, block_off, new_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) struct ocfs2_xattr_header *xh = bucket_xh(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) size_t name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) struct ocfs2_xattr_entry *xe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) char *xe_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) * We don't use binary search in the bucket because there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) * may be multiple entries with the same name hash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) for (i = 0; i < le16_to_cpu(xh->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) xe = &xh->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) if (name_hash > le32_to_cpu(xe->xe_name_hash))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) else if (name_hash < le32_to_cpu(xe->xe_name_hash))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) cmp = name_index - ocfs2_xattr_get_type(xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) if (!cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) cmp = name_len - xe->xe_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) if (cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) &block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) &new_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) xe_name = bucket_block(bucket, block_off) + new_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) if (!memcmp(name, xe_name, name_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) *xe_index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) *found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) * Find the specified xattr entry in a series of buckets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) * This series start from p_blkno and last for num_clusters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) * The ocfs2_xattr_header.xh_num_buckets of the first bucket contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) * the num of the valid buckets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) * Return the buffer_head this xattr should reside in. And if the xattr's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) * hash is in the gap of 2 buckets, return the lower bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) static int ocfs2_xattr_bucket_find(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) u32 name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) u64 p_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) u32 first_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) u32 num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) int ret, found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) struct ocfs2_xattr_header *xh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) struct ocfs2_xattr_entry *xe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) u16 index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) int low_bucket = 0, bucket, high_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) struct ocfs2_xattr_bucket *search;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) u64 blkno, lower_blkno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) search = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) if (!search) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) ret = ocfs2_read_xattr_bucket(search, p_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) xh = bucket_xh(search);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) high_bucket = le16_to_cpu(xh->xh_num_buckets) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) while (low_bucket <= high_bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) ocfs2_xattr_bucket_relse(search);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) bucket = (low_bucket + high_bucket) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) blkno = p_blkno + bucket * blk_per_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) ret = ocfs2_read_xattr_bucket(search, blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) xh = bucket_xh(search);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) xe = &xh->xh_entries[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) if (name_hash < le32_to_cpu(xe->xe_name_hash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) high_bucket = bucket - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) * Check whether the hash of the last entry in our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) * bucket is larger than the search one. for an empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) * bucket, the last one is also the first one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) if (xh->xh_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) xe = &xh->xh_entries[le16_to_cpu(xh->xh_count) - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) /* record lower_blkno which may be the insert place. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) lower_blkno = blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) if (name_hash > le32_to_cpu(xe->xe_name_hash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) low_bucket = bucket + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) /* the searched xattr should reside in this bucket if exists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) ret = ocfs2_find_xe_in_bucket(inode, search,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) name_index, name, name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) &index, &found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) * Record the bucket we have found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) * When the xattr's hash value is in the gap of 2 buckets, we will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) * always set it to the previous bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) if (!lower_blkno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) lower_blkno = p_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) /* This should be in cache - we just read it during the search */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) ret = ocfs2_read_xattr_bucket(xs->bucket, lower_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) xs->header = bucket_xh(xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) xs->base = bucket_block(xs->bucket, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) xs->end = xs->base + inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) if (found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) xs->here = &xs->header->xh_entries[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) trace_ocfs2_xattr_bucket_find(OCFS2_I(inode)->ip_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) name, name_index, name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) (unsigned long long)bucket_blkno(xs->bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) ret = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) ocfs2_xattr_bucket_free(search);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) static int ocfs2_xattr_index_block_find(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) struct ocfs2_xattr_search *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) (struct ocfs2_xattr_block *)root_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) struct ocfs2_extent_list *el = &xb_root->xt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) u64 p_blkno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) u32 first_hash, num_clusters = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) if (le16_to_cpu(el->l_next_free_rec) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) trace_ocfs2_xattr_index_block_find(OCFS2_I(inode)->ip_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) name, name_index, name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) (unsigned long long)root_bh->b_blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, &first_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) &num_clusters, el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) BUG_ON(p_blkno == 0 || num_clusters == 0 || first_hash > name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) trace_ocfs2_xattr_index_block_find_rec(OCFS2_I(inode)->ip_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) name, name_index, first_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) (unsigned long long)p_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) num_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) ret = ocfs2_xattr_bucket_find(inode, name_index, name, name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) p_blkno, first_hash, num_clusters, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) static int ocfs2_iterate_xattr_buckets(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) u64 blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) u32 clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) xattr_bucket_func *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) u32 bpc = ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) u32 num_buckets = clusters * bpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) struct ocfs2_xattr_bucket *bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) if (!bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) mlog_errno(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) trace_ocfs2_iterate_xattr_buckets(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) (unsigned long long)OCFS2_I(inode)->ip_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) (unsigned long long)blkno, clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) for (i = 0; i < num_buckets; i++, blkno += bucket->bu_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) ret = ocfs2_read_xattr_bucket(bucket, blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) * The real bucket num in this series of blocks is stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) * in the 1st bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) if (i == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) num_buckets = le16_to_cpu(bucket_xh(bucket)->xh_num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) trace_ocfs2_iterate_xattr_bucket((unsigned long long)blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) le32_to_cpu(bucket_xh(bucket)->xh_entries[0].xe_name_hash));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) if (func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) ret = func(inode, bucket, para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) if (ret && ret != -ERANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) /* Fall through to bucket_relse() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) ocfs2_xattr_bucket_relse(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) ocfs2_xattr_bucket_free(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) struct ocfs2_xattr_tree_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) size_t buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) size_t result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) int *block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) int *new_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) u16 name_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) if (index < 0 || index >= le16_to_cpu(xh->xh_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) name_offset = le16_to_cpu(xh->xh_entries[index].xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) *block_off = name_offset >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) *new_offset = name_offset % sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) static int ocfs2_list_xattr_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) int ret = 0, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) struct ocfs2_xattr_tree_list *xl = (struct ocfs2_xattr_tree_list *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) int i, block_off, new_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) for (i = 0 ; i < le16_to_cpu(bucket_xh(bucket)->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) struct ocfs2_xattr_entry *entry = &bucket_xh(bucket)->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) type = ocfs2_xattr_get_type(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) bucket_xh(bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) &block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) &new_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) name = (const char *)bucket_block(bucket, block_off) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) new_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) ret = ocfs2_xattr_list_entry(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) xl->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) xl->buffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) &xl->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) type, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) entry->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) static int ocfs2_iterate_xattr_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) struct buffer_head *blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) xattr_tree_rec_func *rec_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) struct ocfs2_extent_list *el = &xb->xb_attrs.xb_root.xt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) u32 name_hash = UINT_MAX, e_cpos = 0, num_clusters = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) u64 p_blkno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) if (!el->l_next_free_rec || !rec_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) while (name_hash > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) &e_cpos, &num_clusters, el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) ret = rec_func(inode, blk_bh, p_blkno, e_cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) num_clusters, para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) if (ret != -ERANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) if (e_cpos == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) name_hash = e_cpos - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) static int ocfs2_list_xattr_tree_rec(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) u64 blkno, u32 cpos, u32 len, void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) return ocfs2_iterate_xattr_buckets(inode, blkno, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) ocfs2_list_xattr_bucket, para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) static int ocfs2_xattr_tree_list_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) struct buffer_head *blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) struct ocfs2_xattr_tree_list xl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) .buffer = buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) .buffer_size = buffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) .result = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) ret = ocfs2_iterate_xattr_index_block(inode, blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) ocfs2_list_xattr_tree_rec, &xl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) ret = xl.result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) static int cmp_xe(const void *a, const void *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) const struct ocfs2_xattr_entry *l = a, *r = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) u32 l_hash = le32_to_cpu(l->xe_name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) u32 r_hash = le32_to_cpu(r->xe_name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) if (l_hash > r_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) if (l_hash < r_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) static void swap_xe(void *a, void *b, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) struct ocfs2_xattr_entry *l = a, *r = b, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) tmp = *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) memcpy(l, r, sizeof(struct ocfs2_xattr_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) memcpy(r, &tmp, sizeof(struct ocfs2_xattr_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) * When the ocfs2_xattr_block is filled up, new bucket will be created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) * and all the xattr entries will be moved to the new bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) * The header goes at the start of the bucket, and the names+values are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) * filled from the end. This is why *target starts as the last buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) * Note: we need to sort the entries since they are not saved in order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) * in the ocfs2_xattr_block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) struct buffer_head *xb_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) struct ocfs2_xattr_bucket *bucket)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) int i, blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) int blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) u16 offset, size, off_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) (struct ocfs2_xattr_block *)xb_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) struct ocfs2_xattr_header *xb_xh = &xb->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) struct ocfs2_xattr_header *xh = bucket_xh(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) u16 count = le16_to_cpu(xb_xh->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) char *src = xb_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) char *target = bucket_block(bucket, blks - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) trace_ocfs2_cp_xattr_block_to_bucket_begin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) (unsigned long long)xb_bh->b_blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) (unsigned long long)bucket_blkno(bucket));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) for (i = 0; i < blks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) memset(bucket_block(bucket, i), 0, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) * Since the xe_name_offset is based on ocfs2_xattr_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) * there is a offset change corresponding to the change of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) * ocfs2_xattr_header's position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) off_change = offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) xe = &xb_xh->xh_entries[count - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) offset = le16_to_cpu(xe->xe_name_offset) + off_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) size = blocksize - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) /* copy all the names and values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) memcpy(target + offset, src + offset, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) /* Init new header now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) xh->xh_count = xb_xh->xh_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) xh->xh_num_buckets = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) xh->xh_name_value_len = cpu_to_le16(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE - size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) /* copy all the entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) target = bucket_block(bucket, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) offset = offsetof(struct ocfs2_xattr_header, xh_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) size = count * sizeof(struct ocfs2_xattr_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) memcpy(target + offset, (char *)xb_xh + offset, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) /* Change the xe offset for all the xe because of the move. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) off_change = OCFS2_XATTR_BUCKET_SIZE - blocksize +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) le16_add_cpu(&xh->xh_entries[i].xe_name_offset, off_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) trace_ocfs2_cp_xattr_block_to_bucket_end(offset, size, off_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) sort(target + offset, count, sizeof(struct ocfs2_xattr_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) cmp_xe, swap_xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) * After we move xattr from block to index btree, we have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) * update ocfs2_xattr_search to the new xe and base.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) * When the entry is in xattr block, xattr_bh indicates the storage place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) * While if the entry is in index b-tree, "bucket" indicates the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) * real place of the xattr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) static void ocfs2_xattr_update_xattr_search(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) struct buffer_head *old_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) char *buf = old_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) struct ocfs2_xattr_block *old_xb = (struct ocfs2_xattr_block *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) struct ocfs2_xattr_header *old_xh = &old_xb->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) xs->header = bucket_xh(xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) xs->base = bucket_block(xs->bucket, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) xs->end = xs->base + inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) if (xs->not_found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) i = xs->here - old_xh->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) xs->here = &xs->header->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) static int ocfs2_xattr_create_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) u32 bit_off, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) u64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) handle_t *handle = ctxt->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) struct buffer_head *xb_bh = xs->xattr_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) (struct ocfs2_xattr_block *)xb_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) struct ocfs2_xattr_tree_root *xr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) u16 xb_flags = le16_to_cpu(xb->xb_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) trace_ocfs2_xattr_create_index_block_begin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) (unsigned long long)xb_bh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) BUG_ON(xb_flags & OCFS2_XATTR_INDEXED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) BUG_ON(!xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) * XXX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) * We can use this lock for now, and maybe move to a dedicated mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) * if performance becomes a problem later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) down_write(&oi->ip_alloc_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), xb_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) ret = __ocfs2_claim_clusters(handle, ctxt->data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 1, 1, &bit_off, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) * The bucket may spread in many blocks, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) * we will only touch the 1st block and the last block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) * in the whole bucket(one for entry and one for data).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) blkno = ocfs2_clusters_to_blocks(inode->i_sb, bit_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) trace_ocfs2_xattr_create_index_block((unsigned long long)blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) ret = ocfs2_init_xattr_bucket(xs->bucket, blkno, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) ret = ocfs2_xattr_bucket_journal_access(handle, xs->bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) OCFS2_JOURNAL_ACCESS_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) ocfs2_cp_xattr_block_to_bucket(inode, xb_bh, xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) ocfs2_xattr_bucket_journal_dirty(handle, xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) ocfs2_xattr_update_xattr_search(inode, xs, xb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) /* Change from ocfs2_xattr_header to ocfs2_xattr_tree_root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) memset(&xb->xb_attrs, 0, inode->i_sb->s_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) offsetof(struct ocfs2_xattr_block, xb_attrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) xr = &xb->xb_attrs.xb_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) xr->xt_clusters = cpu_to_le32(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) xr->xt_last_eb_blk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) xr->xt_list.l_tree_depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) xr->xt_list.l_count = cpu_to_le16(ocfs2_xattr_recs_per_xb(inode->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) xr->xt_list.l_next_free_rec = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) xr->xt_list.l_recs[0].e_cpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) xr->xt_list.l_recs[0].e_blkno = cpu_to_le64(blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) xr->xt_list.l_recs[0].e_leaf_clusters = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) xb->xb_flags = cpu_to_le16(xb_flags | OCFS2_XATTR_INDEXED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) ocfs2_journal_dirty(handle, xb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) up_write(&oi->ip_alloc_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) static int cmp_xe_offset(const void *a, const void *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) const struct ocfs2_xattr_entry *l = a, *r = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) u32 l_name_offset = le16_to_cpu(l->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) u32 r_name_offset = le16_to_cpu(r->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) if (l_name_offset < r_name_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) if (l_name_offset > r_name_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) * defrag a xattr bucket if we find that the bucket has some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) * holes beteen name/value pairs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) * We will move all the name/value pairs to the end of the bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) * so that we can spare some space for insertion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) static int ocfs2_defrag_xattr_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) struct ocfs2_xattr_bucket *bucket)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) size_t end, offset, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) struct ocfs2_xattr_header *xh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) char *entries, *buf, *bucket_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) u64 blkno = bucket_blkno(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) u16 xh_free_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) size_t blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) * In order to make the operation more efficient and generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) * we copy all the blocks into a contiguous memory and do the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) * defragment there, so if anything is error, we will not touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) * the real block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) bucket_buf = kmalloc(OCFS2_XATTR_BUCKET_SIZE, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) if (!bucket_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) buf = bucket_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) for (i = 0; i < bucket->bu_blocks; i++, buf += blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) memcpy(buf, bucket_block(bucket, i), blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) ret = ocfs2_xattr_bucket_journal_access(handle, bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) xh = (struct ocfs2_xattr_header *)bucket_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) entries = (char *)xh->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) xh_free_start = le16_to_cpu(xh->xh_free_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) trace_ocfs2_defrag_xattr_bucket(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) (unsigned long long)blkno, le16_to_cpu(xh->xh_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) xh_free_start, le16_to_cpu(xh->xh_name_value_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) * sort all the entries by their offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) * the largest will be the first, so that we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) * move them to the end one by one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) sort(entries, le16_to_cpu(xh->xh_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) sizeof(struct ocfs2_xattr_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) cmp_xe_offset, swap_xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) /* Move all name/values to the end of the bucket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) xe = xh->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) end = OCFS2_XATTR_BUCKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) for (i = 0; i < le16_to_cpu(xh->xh_count); i++, xe++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) offset = le16_to_cpu(xe->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) len = namevalue_size_xe(xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) * We must make sure that the name/value pair
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) * exist in the same block. So adjust end to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) * the previous block end if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) if (((end - len) / blocksize !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) (end - 1) / blocksize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) end = end - end % blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) if (end > offset + len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) memmove(bucket_buf + end - len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) bucket_buf + offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) xe->xe_name_offset = cpu_to_le16(end - len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) mlog_bug_on_msg(end < offset + len, "Defrag check failed for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) "bucket %llu\n", (unsigned long long)blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) end -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) mlog_bug_on_msg(xh_free_start > end, "Defrag check failed for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) "bucket %llu\n", (unsigned long long)blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) if (xh_free_start == end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) memset(bucket_buf + xh_free_start, 0, end - xh_free_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) xh->xh_free_start = cpu_to_le16(end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) /* sort the entries by their name_hash. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) sort(entries, le16_to_cpu(xh->xh_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) sizeof(struct ocfs2_xattr_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) cmp_xe, swap_xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) buf = bucket_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) for (i = 0; i < bucket->bu_blocks; i++, buf += blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) memcpy(bucket_block(bucket, i), buf, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) ocfs2_xattr_bucket_journal_dirty(handle, bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) kfree(bucket_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) * prev_blkno points to the start of an existing extent. new_blkno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) * points to a newly allocated extent. Because we know each of our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) * clusters contains more than bucket, we can easily split one cluster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) * at a bucket boundary. So we take the last cluster of the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) * extent and split it down the middle. We move the last half of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) * buckets in the last cluster of the existing extent over to the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) * extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) * first_bh is the buffer at prev_blkno so we can update the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) * extent's bucket count. header_bh is the bucket were we were hoping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) * to insert our xattr. If the bucket move places the target in the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) * extent, we'll update first_bh and header_bh after modifying the old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) * extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) * first_hash will be set as the 1st xe's name_hash in the new extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) static int ocfs2_mv_xattr_bucket_cross_cluster(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) struct ocfs2_xattr_bucket *first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) struct ocfs2_xattr_bucket *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) u64 new_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) u32 num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) u32 *first_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) int blks_per_bucket = ocfs2_blocks_per_xattr_bucket(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) int num_buckets = ocfs2_xattr_buckets_per_cluster(OCFS2_SB(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) int to_move = num_buckets / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) u64 src_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) u64 last_cluster_blkno = bucket_blkno(first) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) ((num_clusters - 1) * ocfs2_clusters_to_blocks(sb, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) BUG_ON(le16_to_cpu(bucket_xh(first)->xh_num_buckets) < num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) BUG_ON(OCFS2_XATTR_BUCKET_SIZE == OCFS2_SB(sb)->s_clustersize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) trace_ocfs2_mv_xattr_bucket_cross_cluster(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) (unsigned long long)last_cluster_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) (unsigned long long)new_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) ret = ocfs2_mv_xattr_buckets(inode, handle, bucket_blkno(first),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) last_cluster_blkno, new_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) to_move, first_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) /* This is the first bucket that got moved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) src_blkno = last_cluster_blkno + (to_move * blks_per_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) * If the target bucket was part of the moved buckets, we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) * update first and target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) if (bucket_blkno(target) >= src_blkno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) /* Find the block for the new target bucket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) src_blkno = new_blkno +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) (bucket_blkno(target) - src_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) ocfs2_xattr_bucket_relse(first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) ocfs2_xattr_bucket_relse(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) * These shouldn't fail - the buffers are in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) * journal from ocfs2_cp_xattr_bucket().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) ret = ocfs2_read_xattr_bucket(first, new_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) ret = ocfs2_read_xattr_bucket(target, src_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) * Find the suitable pos when we divide a bucket into 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) * We have to make sure the xattrs with the same hash value exist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) * in the same bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) * If this ocfs2_xattr_header covers more than one hash value, find a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) * place where the hash value changes. Try to find the most even split.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) * The most common case is that all entries have different hash values,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) * and the first check we make will find a place to split.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) static int ocfs2_xattr_find_divide_pos(struct ocfs2_xattr_header *xh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) struct ocfs2_xattr_entry *entries = xh->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) int count = le16_to_cpu(xh->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) int delta, middle = count / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) * We start at the middle. Each step gets farther away in both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) * directions. We therefore hit the change in hash value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) * nearest to the middle. Note that this loop does not execute for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) * count < 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) for (delta = 0; delta < middle; delta++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) /* Let's check delta earlier than middle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) if (cmp_xe(&entries[middle - delta - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) &entries[middle - delta]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) return middle - delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) /* For even counts, don't walk off the end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) if ((middle + delta + 1) == count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) /* Now try delta past middle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) if (cmp_xe(&entries[middle + delta],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) &entries[middle + delta + 1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) return middle + delta + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) /* Every entry had the same hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) * Move some xattrs in old bucket(blk) to new bucket(new_blk).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) * first_hash will record the 1st hash of the new bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) * Normally half of the xattrs will be moved. But we have to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) * sure that the xattrs with the same hash value are stored in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) * same bucket. If all the xattrs in this bucket have the same hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) * value, the new bucket will be initialized as an empty one and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) * first_hash will be initialized as (hash_value+1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) static int ocfs2_divide_xattr_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) u64 blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) u64 new_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) u32 *first_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) int new_bucket_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) int count, start, len, name_value_len = 0, name_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) struct ocfs2_xattr_bucket *s_bucket = NULL, *t_bucket = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) struct ocfs2_xattr_header *xh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) int blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) trace_ocfs2_divide_xattr_bucket_begin((unsigned long long)blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) (unsigned long long)new_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) s_bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) t_bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) if (!s_bucket || !t_bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) ret = ocfs2_read_xattr_bucket(s_bucket, blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) ret = ocfs2_xattr_bucket_journal_access(handle, s_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) * Even if !new_bucket_head, we're overwriting t_bucket. Thus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) * there's no need to read it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) ret = ocfs2_init_xattr_bucket(t_bucket, new_blk, new_bucket_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) * Hey, if we're overwriting t_bucket, what difference does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) * ACCESS_CREATE vs ACCESS_WRITE make? See the comment in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) * same part of ocfs2_cp_xattr_bucket().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) ret = ocfs2_xattr_bucket_journal_access(handle, t_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) new_bucket_head ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) OCFS2_JOURNAL_ACCESS_CREATE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) xh = bucket_xh(s_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) count = le16_to_cpu(xh->xh_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) start = ocfs2_xattr_find_divide_pos(xh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) if (start == count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) xe = &xh->xh_entries[start-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) * initialized a new empty bucket here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) * The hash value is set as one larger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) * that of the last entry in the previous bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) for (i = 0; i < t_bucket->bu_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) memset(bucket_block(t_bucket, i), 0, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) xh = bucket_xh(t_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) xh->xh_free_start = cpu_to_le16(blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) xh->xh_entries[0].xe_name_hash = xe->xe_name_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) le32_add_cpu(&xh->xh_entries[0].xe_name_hash, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) goto set_num_buckets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) /* copy the whole bucket to the new first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) ocfs2_xattr_bucket_copy_data(t_bucket, s_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) /* update the new bucket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) xh = bucket_xh(t_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) * Calculate the total name/value len and xh_free_start for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) * the old bucket first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) name_offset = OCFS2_XATTR_BUCKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) name_value_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) for (i = 0; i < start; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) xe = &xh->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) name_value_len += namevalue_size_xe(xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) if (le16_to_cpu(xe->xe_name_offset) < name_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) name_offset = le16_to_cpu(xe->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) * Now begin the modification to the new bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) * In the new bucket, We just move the xattr entry to the beginning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) * and don't touch the name/value. So there will be some holes in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) * bucket, and they will be removed when ocfs2_defrag_xattr_bucket is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) * called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) xe = &xh->xh_entries[start];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) len = sizeof(struct ocfs2_xattr_entry) * (count - start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) trace_ocfs2_divide_xattr_bucket_move(len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) (int)((char *)xe - (char *)xh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) (int)((char *)xh->xh_entries - (char *)xh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) memmove((char *)xh->xh_entries, (char *)xe, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) xe = &xh->xh_entries[count - start];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) len = sizeof(struct ocfs2_xattr_entry) * start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) memset((char *)xe, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) le16_add_cpu(&xh->xh_count, -start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) le16_add_cpu(&xh->xh_name_value_len, -name_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) /* Calculate xh_free_start for the new bucket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) for (i = 0; i < le16_to_cpu(xh->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) xe = &xh->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) if (le16_to_cpu(xe->xe_name_offset) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) le16_to_cpu(xh->xh_free_start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) xh->xh_free_start = xe->xe_name_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) set_num_buckets:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) /* set xh->xh_num_buckets for the new xh. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) if (new_bucket_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) xh->xh_num_buckets = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) xh->xh_num_buckets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) ocfs2_xattr_bucket_journal_dirty(handle, t_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) /* store the first_hash of the new bucket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) if (first_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) *first_hash = le32_to_cpu(xh->xh_entries[0].xe_name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) * Now only update the 1st block of the old bucket. If we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) * just added a new empty bucket, there is no need to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) if (start == count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) xh = bucket_xh(s_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) memset(&xh->xh_entries[start], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) sizeof(struct ocfs2_xattr_entry) * (count - start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) xh->xh_count = cpu_to_le16(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) xh->xh_free_start = cpu_to_le16(name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) xh->xh_name_value_len = cpu_to_le16(name_value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) ocfs2_xattr_bucket_journal_dirty(handle, s_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) ocfs2_xattr_bucket_free(s_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) ocfs2_xattr_bucket_free(t_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) * Copy xattr from one bucket to another bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) * The caller must make sure that the journal transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) * has enough space for journaling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) static int ocfs2_cp_xattr_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) u64 s_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) u64 t_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) int t_is_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) struct ocfs2_xattr_bucket *s_bucket = NULL, *t_bucket = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) BUG_ON(s_blkno == t_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) trace_ocfs2_cp_xattr_bucket((unsigned long long)s_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) (unsigned long long)t_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) t_is_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) s_bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) t_bucket = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) if (!s_bucket || !t_bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) ret = ocfs2_read_xattr_bucket(s_bucket, s_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) * Even if !t_is_new, we're overwriting t_bucket. Thus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) * there's no need to read it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) ret = ocfs2_init_xattr_bucket(t_bucket, t_blkno, t_is_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) * Hey, if we're overwriting t_bucket, what difference does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) * ACCESS_CREATE vs ACCESS_WRITE make? Well, if we allocated a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) * cluster to fill, we came here from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) * ocfs2_mv_xattr_buckets(), and it is really new -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) * ACCESS_CREATE is required. But we also might have moved data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) * out of t_bucket before extending back into it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) * ocfs2_add_new_xattr_bucket() can do this - its call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) * ocfs2_add_new_xattr_cluster() may have created a new extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) * and copied out the end of the old extent. Then it re-extends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) * the old extent back to create space for new xattrs. That's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) * how we get here, and the bucket isn't really new.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) ret = ocfs2_xattr_bucket_journal_access(handle, t_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) t_is_new ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) OCFS2_JOURNAL_ACCESS_CREATE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) ocfs2_xattr_bucket_copy_data(t_bucket, s_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) ocfs2_xattr_bucket_journal_dirty(handle, t_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) ocfs2_xattr_bucket_free(t_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) ocfs2_xattr_bucket_free(s_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) * src_blk points to the start of an existing extent. last_blk points to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) * last cluster in that extent. to_blk points to a newly allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) * extent. We copy the buckets from the cluster at last_blk to the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) * extent. If start_bucket is non-zero, we skip that many buckets before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) * we start copying. The new extent's xh_num_buckets gets set to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) * number of buckets we copied. The old extent's xh_num_buckets shrinks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) * by the same amount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) static int ocfs2_mv_xattr_buckets(struct inode *inode, handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) u64 src_blk, u64 last_blk, u64 to_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) unsigned int start_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) u32 *first_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) int i, ret, credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) int blks_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) int num_buckets = ocfs2_xattr_buckets_per_cluster(osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) struct ocfs2_xattr_bucket *old_first, *new_first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) trace_ocfs2_mv_xattr_buckets((unsigned long long)last_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) (unsigned long long)to_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) BUG_ON(start_bucket >= num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) if (start_bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) num_buckets -= start_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) last_blk += (start_bucket * blks_per_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) /* The first bucket of the original extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) old_first = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) /* The first bucket of the new extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) new_first = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) if (!old_first || !new_first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) ret = ocfs2_read_xattr_bucket(old_first, src_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) * We need to update the first bucket of the old extent and all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) * the buckets going to the new extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) credits = ((num_buckets + 1) * blks_per_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) ret = ocfs2_extend_trans(handle, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) ret = ocfs2_xattr_bucket_journal_access(handle, old_first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) for (i = 0; i < num_buckets; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) ret = ocfs2_cp_xattr_bucket(inode, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) last_blk + (i * blks_per_bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) to_blk + (i * blks_per_bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) * Get the new bucket ready before we dirty anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) * (This actually shouldn't fail, because we already dirtied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) * it once in ocfs2_cp_xattr_bucket()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) ret = ocfs2_read_xattr_bucket(new_first, to_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) ret = ocfs2_xattr_bucket_journal_access(handle, new_first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) /* Now update the headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) le16_add_cpu(&bucket_xh(old_first)->xh_num_buckets, -num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) ocfs2_xattr_bucket_journal_dirty(handle, old_first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) bucket_xh(new_first)->xh_num_buckets = cpu_to_le16(num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) ocfs2_xattr_bucket_journal_dirty(handle, new_first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) if (first_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) *first_hash = le32_to_cpu(bucket_xh(new_first)->xh_entries[0].xe_name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) ocfs2_xattr_bucket_free(new_first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) ocfs2_xattr_bucket_free(old_first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) * Move some xattrs in this cluster to the new cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) * This function should only be called when bucket size == cluster size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) * Otherwise ocfs2_mv_xattr_bucket_cross_cluster should be used instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) static int ocfs2_divide_xattr_cluster(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) u64 prev_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) u64 new_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) u32 *first_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) int ret, credits = 2 * blk_per_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) BUG_ON(OCFS2_XATTR_BUCKET_SIZE < OCFS2_SB(inode->i_sb)->s_clustersize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) ret = ocfs2_extend_trans(handle, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) /* Move half of the xattr in start_blk to the next bucket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) return ocfs2_divide_xattr_bucket(inode, handle, prev_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) new_blk, first_hash, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) * Move some xattrs from the old cluster to the new one since they are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) * contiguous in ocfs2 xattr tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) * new_blk starts a new separate cluster, and we will move some xattrs from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) * prev_blk to it. v_start will be set as the first name hash value in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) * new cluster so that it can be used as e_cpos during tree insertion and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) * don't collide with our original b-tree operations. first_bh and header_bh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) * will also be updated since they will be used in ocfs2_extend_xattr_bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) * to extend the insert bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) * The problem is how much xattr should we move to the new one and when should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) * we update first_bh and header_bh?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) * 1. If cluster size > bucket size, that means the previous cluster has more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) * than 1 bucket, so just move half nums of bucket into the new cluster and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) * update the first_bh and header_bh if the insert bucket has been moved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) * to the new cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) * 2. If cluster_size == bucket_size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) * a) If the previous extent rec has more than one cluster and the insert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) * place isn't in the last cluster, copy the entire last cluster to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) * new one. This time, we don't need to upate the first_bh and header_bh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) * since they will not be moved into the new cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) * b) Otherwise, move the bottom half of the xattrs in the last cluster into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) * the new one. And we set the extend flag to zero if the insert place is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) * moved into the new allocated cluster since no extend is needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) static int ocfs2_adjust_xattr_cross_cluster(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) struct ocfs2_xattr_bucket *first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) struct ocfs2_xattr_bucket *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) u64 new_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) u32 prev_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) u32 *v_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) int *extend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) trace_ocfs2_adjust_xattr_cross_cluster(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) (unsigned long long)bucket_blkno(first),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) (unsigned long long)new_blk, prev_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) if (ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb)) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) ret = ocfs2_mv_xattr_bucket_cross_cluster(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) first, target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) new_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) prev_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) v_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) /* The start of the last cluster in the first extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) u64 last_blk = bucket_blkno(first) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) ((prev_clusters - 1) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) ocfs2_clusters_to_blocks(inode->i_sb, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) if (prev_clusters > 1 && bucket_blkno(target) != last_blk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) ret = ocfs2_mv_xattr_buckets(inode, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) bucket_blkno(first),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) last_blk, new_blk, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) v_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) ret = ocfs2_divide_xattr_cluster(inode, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) last_blk, new_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) v_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) if ((bucket_blkno(target) == last_blk) && extend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) *extend = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) * Add a new cluster for xattr storage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) * If the new cluster is contiguous with the previous one, it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) * appended to the same extent record, and num_clusters will be updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) * If not, we will insert a new extent for it and move some xattrs in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) * the last cluster into the new allocated one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) * We also need to limit the maximum size of a btree leaf, otherwise we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) * lose the benefits of hashing because we'll have to search large leaves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) * So now the maximum size is OCFS2_MAX_XATTR_TREE_LEAF_SIZE(or clustersize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) * if it's bigger).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) * first_bh is the first block of the previous extent rec and header_bh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) * indicates the bucket we will insert the new xattrs. They will be updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) * when the header_bh is moved into the new cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) static int ocfs2_add_new_xattr_cluster(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) struct ocfs2_xattr_bucket *first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) struct ocfs2_xattr_bucket *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) u32 *num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) u32 prev_cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) int *extend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) u16 bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) u32 prev_clusters = *num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) u32 clusters_to_add = 1, bit_off, num_bits, v_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) u64 block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) handle_t *handle = ctxt->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) struct ocfs2_extent_tree et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) trace_ocfs2_add_new_xattr_cluster_begin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) (unsigned long long)OCFS2_I(inode)->ip_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) (unsigned long long)bucket_blkno(first),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) prev_cpos, prev_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) ocfs2_init_xattr_tree_extent_tree(&et, INODE_CACHE(inode), root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) ret = __ocfs2_claim_clusters(handle, ctxt->data_ac, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) clusters_to_add, &bit_off, &num_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) if (ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) BUG_ON(num_bits > clusters_to_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) block = ocfs2_clusters_to_blocks(osb->sb, bit_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) trace_ocfs2_add_new_xattr_cluster((unsigned long long)block, num_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) if (bucket_blkno(first) + (prev_clusters * bpc) == block &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) (prev_clusters + num_bits) << osb->s_clustersize_bits <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) OCFS2_MAX_XATTR_TREE_LEAF_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) * If this cluster is contiguous with the old one and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) * adding this new cluster, we don't surpass the limit of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) * OCFS2_MAX_XATTR_TREE_LEAF_SIZE, cool. We will let it be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) * initialized and used like other buckets in the previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) * cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) * So add it as a contiguous one. The caller will handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) * its init process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) v_start = prev_cpos + prev_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) *num_clusters = prev_clusters + num_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) ret = ocfs2_adjust_xattr_cross_cluster(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) prev_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) &v_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) extend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) trace_ocfs2_add_new_xattr_cluster_insert((unsigned long long)block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) v_start, num_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) ret = ocfs2_insert_extent(handle, &et, v_start, block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) num_bits, 0, ctxt->meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) ocfs2_journal_dirty(handle, root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) * We are given an extent. 'first' is the bucket at the very front of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) * the extent. The extent has space for an additional bucket past
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) * bucket_xh(first)->xh_num_buckets. 'target_blkno' is the block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) * of the target bucket. We wish to shift every bucket past the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) * down one, filling in that additional space. When we get back to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) * target, we split the target between itself and the now-empty bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) * at target+1 (aka, target_blkno + blks_per_bucket).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) static int ocfs2_extend_xattr_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) struct ocfs2_xattr_bucket *first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) u64 target_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) u32 num_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) int ret, credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) u64 end_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) u16 new_bucket = le16_to_cpu(bucket_xh(first)->xh_num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) trace_ocfs2_extend_xattr_bucket((unsigned long long)target_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) (unsigned long long)bucket_blkno(first),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) num_clusters, new_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) /* The extent must have room for an additional bucket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) BUG_ON(new_bucket >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) (num_clusters * ocfs2_xattr_buckets_per_cluster(osb)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) /* end_blk points to the last existing bucket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) end_blk = bucket_blkno(first) + ((new_bucket - 1) * blk_per_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) * end_blk is the start of the last existing bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) * Thus, (end_blk - target_blk) covers the target bucket and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) * every bucket after it up to, but not including, the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) * existing bucket. Then we add the last existing bucket, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) * new bucket, and the first bucket (3 * blk_per_bucket).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) credits = (end_blk - target_blk) + (3 * blk_per_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) ret = ocfs2_extend_trans(handle, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) ret = ocfs2_xattr_bucket_journal_access(handle, first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) while (end_blk != target_blk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) ret = ocfs2_cp_xattr_bucket(inode, handle, end_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) end_blk + blk_per_bucket, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) end_blk -= blk_per_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) /* Move half of the xattr in target_blkno to the next bucket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) ret = ocfs2_divide_xattr_bucket(inode, handle, target_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) target_blk + blk_per_bucket, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) le16_add_cpu(&bucket_xh(first)->xh_num_buckets, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) ocfs2_xattr_bucket_journal_dirty(handle, first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) * Add new xattr bucket in an extent record and adjust the buckets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) * accordingly. xb_bh is the ocfs2_xattr_block, and target is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) * bucket we want to insert into.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) * In the easy case, we will move all the buckets after target down by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) * one. Half of target's xattrs will be moved to the next bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) * If current cluster is full, we'll allocate a new one. This may not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) * be contiguous. The underlying calls will make sure that there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) * space for the insert, shifting buckets around if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) * 'target' may be moved by those calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) static int ocfs2_add_new_xattr_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) struct buffer_head *xb_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) struct ocfs2_xattr_bucket *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) (struct ocfs2_xattr_block *)xb_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) struct ocfs2_extent_list *el = &xb_root->xt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) u32 name_hash =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) le32_to_cpu(bucket_xh(target)->xh_entries[0].xe_name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) int ret, num_buckets, extend = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) u64 p_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) u32 e_cpos, num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) /* The bucket at the front of the extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) struct ocfs2_xattr_bucket *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) trace_ocfs2_add_new_xattr_bucket(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) (unsigned long long)bucket_blkno(target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) /* The first bucket of the original extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) first = ocfs2_xattr_bucket_new(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) if (!first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, &e_cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) &num_clusters, el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) ret = ocfs2_read_xattr_bucket(first, p_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) num_buckets = ocfs2_xattr_buckets_per_cluster(osb) * num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) if (num_buckets == le16_to_cpu(bucket_xh(first)->xh_num_buckets)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) * This can move first+target if the target bucket moves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) * to the new extent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) ret = ocfs2_add_new_xattr_cluster(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) xb_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) &num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) e_cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) &extend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) if (extend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) ret = ocfs2_extend_xattr_bucket(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) ctxt->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) bucket_blkno(target),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) num_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) ocfs2_xattr_bucket_free(first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) * Truncate the specified xe_off entry in xattr bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) * bucket is indicated by header_bh and len is the new length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) * Both the ocfs2_xattr_value_root and the entry will be updated here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) * Copy the new updated xe and xe_value_root to new_xe and new_xv if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) static int ocfs2_xattr_bucket_value_truncate(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) int xe_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) int ret, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) u64 value_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) struct ocfs2_xattr_header *xh = bucket_xh(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) size_t blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) .vb_access = ocfs2_journal_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) xe = &xh->xh_entries[xe_off];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) BUG_ON(!xe || ocfs2_xattr_is_local(xe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) offset = le16_to_cpu(xe->xe_name_offset) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) OCFS2_XATTR_SIZE(xe->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) value_blk = offset / blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) /* We don't allow ocfs2_xattr_value to be stored in different block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) BUG_ON(value_blk != (offset + OCFS2_XATTR_ROOT_SIZE - 1) / blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) vb.vb_bh = bucket->bu_bhs[value_blk];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) BUG_ON(!vb.vb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) vb.vb_xv = (struct ocfs2_xattr_value_root *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) (vb.vb_bh->b_data + offset % blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) * From here on out we have to dirty the bucket. The generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) * value calls only modify one of the bucket's bhs, but we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) * to send the bucket at once. So if they error, they *could* have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) * modified something. We have to assume they did, and dirty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) * the whole bucket. This leaves us in a consistent state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) trace_ocfs2_xattr_bucket_value_truncate(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) (unsigned long long)bucket_blkno(bucket), xe_off, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) ret = ocfs2_xattr_value_truncate(inode, &vb, len, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) ret = ocfs2_xattr_bucket_journal_access(ctxt->handle, bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) xe->xe_value_size = cpu_to_le64(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) ocfs2_xattr_bucket_journal_dirty(ctxt->handle, bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) static int ocfs2_rm_xattr_cluster(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) u64 blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) u32 cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) struct inode *tl_inode = osb->osb_tl_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) (struct ocfs2_xattr_block *)root_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) struct ocfs2_alloc_context *meta_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) struct ocfs2_cached_dealloc_ctxt dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) struct ocfs2_extent_tree et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) ret = ocfs2_iterate_xattr_buckets(inode, blkno, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) ocfs2_delete_xattr_in_bucket, para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) ocfs2_init_xattr_tree_extent_tree(&et, INODE_CACHE(inode), root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) ocfs2_init_dealloc_ctxt(&dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) trace_ocfs2_rm_xattr_cluster(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) (unsigned long long)OCFS2_I(inode)->ip_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) (unsigned long long)blkno, cpos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) ocfs2_remove_xattr_clusters_from_cache(INODE_CACHE(inode), blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) inode_lock(tl_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) if (ocfs2_truncate_log_needs_flush(osb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) ret = __ocfs2_flush_truncate_log(osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) handle = ocfs2_start_trans(osb, ocfs2_remove_extent_credits(osb->sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) ret = ocfs2_remove_extent(handle, &et, cpos, len, meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) &dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, -len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) ocfs2_journal_dirty(handle, root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) ret = ocfs2_truncate_log_append(osb, handle, blkno, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) ocfs2_update_inode_fsync_trans(handle, inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) out_commit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) ocfs2_schedule_truncate_log_flush(osb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) inode_unlock(tl_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) if (meta_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) ocfs2_free_alloc_context(meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) ocfs2_run_deallocs(osb, &dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) * check whether the xattr bucket is filled up with the same hash value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) * If we want to insert the xattr with the same hash, return -ENOSPC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) * If we want to insert a xattr with different hash value, go ahead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) * and ocfs2_divide_xattr_bucket will handle this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) static int ocfs2_check_xattr_bucket_collision(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) struct ocfs2_xattr_header *xh = bucket_xh(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) if (xh->xh_entries[le16_to_cpu(xh->xh_count) - 1].xe_name_hash ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) xh->xh_entries[0].xe_name_hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) "hash = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) (unsigned long long)bucket_blkno(bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) le32_to_cpu(xh->xh_entries[0].xe_name_hash));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) * Try to set the entry in the current bucket. If we fail, the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) * will handle getting us another bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) static int ocfs2_xattr_set_entry_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) struct ocfs2_xa_loc loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) trace_ocfs2_xattr_set_entry_bucket(xi->xi_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) ocfs2_init_xattr_bucket_xa_loc(&loc, xs->bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) xs->not_found ? NULL : xs->here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) ret = ocfs2_xa_set(&loc, xi, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) xs->here = loc.xl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) if (ret != -ENOSPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) /* Ok, we need space. Let's try defragmenting the bucket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) ret = ocfs2_defrag_xattr_bucket(inode, ctxt->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) ret = ocfs2_xa_set(&loc, xi, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) xs->here = loc.xl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) if (ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) static int ocfs2_xattr_set_entry_index_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) struct ocfs2_xattr_search *xs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) struct ocfs2_xattr_set_ctxt *ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) trace_ocfs2_xattr_set_entry_index_block(xi->xi_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) ret = ocfs2_xattr_set_entry_bucket(inode, xi, xs, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) if (ret != -ENOSPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) /* Ack, need more space. Let's try to get another bucket! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) * We do not allow for overlapping ranges between buckets. And
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) * the maximum number of collisions we will allow for then is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) * one bucket's worth, so check it here whether we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) * add a new bucket for the insert.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) ret = ocfs2_check_xattr_bucket_collision(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) xs->bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) xi->xi_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) ret = ocfs2_add_new_xattr_bucket(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) xs->xattr_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) xs->bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) * ocfs2_add_new_xattr_bucket() will have updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) * xs->bucket if it moved, but it will not have updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) * any of the other search fields. Thus, we drop it and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) * re-search. Everything should be cached, so it'll be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) * quick.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) ocfs2_xattr_bucket_relse(xs->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) ret = ocfs2_xattr_index_block_find(inode, xs->xattr_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) xi->xi_name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) xi->xi_name, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) if (ret && ret != -ENODATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) xs->not_found = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) /* Ok, we have a new bucket, let's try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) ret = ocfs2_xattr_set_entry_bucket(inode, xi, xs, ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) if (ret && (ret != -ENOSPC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) static int ocfs2_delete_xattr_in_bucket(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) int ret = 0, ref_credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) struct ocfs2_xattr_header *xh = bucket_xh(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) u16 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) struct ocfs2_xattr_set_ctxt ctxt = {NULL, NULL,};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) int credits = ocfs2_remove_extent_credits(osb->sb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) ocfs2_blocks_per_xattr_bucket(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) struct ocfs2_xattr_value_root *xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) struct ocfs2_rm_xattr_bucket_para *args =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) (struct ocfs2_rm_xattr_bucket_para *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) ocfs2_init_dealloc_ctxt(&ctxt.dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) for (i = 0; i < le16_to_cpu(xh->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) xe = &xh->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) if (ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) ret = ocfs2_get_xattr_tree_value_root(inode->i_sb, bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) i, &xv, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) ret = ocfs2_lock_xattr_remove_allocators(inode, xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) args->ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) args->ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) &ctxt.meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) &ref_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) ctxt.handle = ocfs2_start_trans(osb, credits + ref_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) if (IS_ERR(ctxt.handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) ret = PTR_ERR(ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) ret = ocfs2_xattr_bucket_value_truncate(inode, bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) i, 0, &ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) ocfs2_commit_trans(osb, ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) if (ctxt.meta_ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) ocfs2_free_alloc_context(ctxt.meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) ctxt.meta_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) if (ctxt.meta_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) ocfs2_free_alloc_context(ctxt.meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) ocfs2_schedule_truncate_log_flush(osb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) ocfs2_run_deallocs(osb, &ctxt.dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) * Whenever we modify a xattr value root in the bucket(e.g, CoW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) * or change the extent record flag), we need to recalculate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) * the metaecc for the whole bucket. So it is done here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) * Note:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) * We have to give the extra credits for the caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) static int ocfs2_xattr_bucket_post_refcount(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) struct ocfs2_xattr_bucket *bucket =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) (struct ocfs2_xattr_bucket *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) ret = ocfs2_xattr_bucket_journal_access(handle, bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) ocfs2_xattr_bucket_journal_dirty(handle, bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) * Special action we need if the xattr value is refcounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) * 1. If the xattr is refcounted, lock the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) * 2. CoW the xattr if we are setting the new value and the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) * will be stored outside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) * 3. In other case, decrease_refcount will work for us, so just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) * lock the refcount tree, calculate the meta and credits is OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) * We have to do CoW before ocfs2_init_xattr_set_ctxt since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) * currently CoW is a completed transaction, while this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) * will also lock the allocators and let us deadlock. So we will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) * CoW the whole xattr value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) static int ocfs2_prepare_refcount_xattr(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) struct ocfs2_dinode *di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) struct ocfs2_xattr_info *xi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) struct ocfs2_xattr_search *xis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) struct ocfs2_xattr_search *xbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) struct ocfs2_refcount_tree **ref_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) int *meta_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) int *credits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) struct ocfs2_xattr_block *xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) char *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) u32 p_cluster, num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) unsigned int ext_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) int name_offset, name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) struct ocfs2_xattr_value_buf vb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) struct ocfs2_xattr_bucket *bucket = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) struct ocfs2_post_refcount refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) struct ocfs2_post_refcount *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) struct buffer_head *ref_root_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) if (!xis->not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) xe = xis->here;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) name_offset = le16_to_cpu(xe->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) name_len = OCFS2_XATTR_SIZE(xe->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) base = xis->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) vb.vb_bh = xis->inode_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) vb.vb_access = ocfs2_journal_access_di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) int i, block_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) xb = (struct ocfs2_xattr_block *)xbs->xattr_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) xe = xbs->here;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) name_offset = le16_to_cpu(xe->xe_name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) name_len = OCFS2_XATTR_SIZE(xe->xe_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) i = xbs->here - xbs->header->xh_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) bucket_xh(xbs->bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) i, &block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) &name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) base = bucket_block(xbs->bucket, block_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) vb.vb_bh = xbs->bucket->bu_bhs[block_off];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) vb.vb_access = ocfs2_journal_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) if (ocfs2_meta_ecc(osb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) /*create parameters for ocfs2_post_refcount. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) bucket = xbs->bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) refcount.credits = bucket->bu_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) refcount.para = bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) refcount.func =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) ocfs2_xattr_bucket_post_refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) p = &refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) base = xbs->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) vb.vb_bh = xbs->xattr_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) vb.vb_access = ocfs2_journal_access_xb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) if (ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) vb.vb_xv = (struct ocfs2_xattr_value_root *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) (base + name_offset + name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) ret = ocfs2_xattr_get_clusters(inode, 0, &p_cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) &num_clusters, &vb.vb_xv->xr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) &ext_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) * We just need to check the 1st extent record, since we always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) * CoW the whole xattr. So there shouldn't be a xattr with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) * some REFCOUNT extent recs after the 1st one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) if (!(ext_flags & OCFS2_EXT_REFCOUNTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) ret = ocfs2_lock_refcount_tree(osb, le64_to_cpu(di->i_refcount_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) 1, ref_tree, &ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) * If we are deleting the xattr or the new size will be stored inside,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) * cool, leave it there, the xattr truncate process will remove them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) * for us(it still needs the refcount tree lock and the meta, credits).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) * And the worse case is that every cluster truncate will split the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) * refcount tree, and make the original extent become 3. So we will need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) * 2 * cluster more extent recs at most.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) if (!xi->xi_value || xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) ret = ocfs2_refcounted_xattr_delete_need(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) &(*ref_tree)->rf_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) ref_root_bh, vb.vb_xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) meta_add, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) ret = ocfs2_refcount_cow_xattr(inode, di, &vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) *ref_tree, ref_root_bh, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) le32_to_cpu(vb.vb_xv->xr_clusters), p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) brelse(ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) * Add the REFCOUNTED flags for all the extent rec in ocfs2_xattr_value_root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) * The physical clusters will be added to refcount tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) static int ocfs2_xattr_value_attach_refcount(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) struct ocfs2_xattr_value_root *xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) struct ocfs2_extent_tree *value_et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) struct buffer_head *ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) struct ocfs2_cached_dealloc_ctxt *dealloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) struct ocfs2_post_refcount *refcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) u32 clusters = le32_to_cpu(xv->xr_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) u32 cpos, p_cluster, num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) struct ocfs2_extent_list *el = &xv->xr_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) unsigned int ext_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) cpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) while (cpos < clusters) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) &num_clusters, el, &ext_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) cpos += num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) if ((ext_flags & OCFS2_EXT_REFCOUNTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) BUG_ON(!p_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) ret = ocfs2_add_refcount_flag(inode, value_et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) ref_ci, ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) cpos - num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) p_cluster, num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) dealloc, refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) * Given a normal ocfs2_xattr_header, refcount all the entries which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) * have value stored outside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) * Used for xattrs stored in inode and ocfs2_xattr_block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) static int ocfs2_xattr_attach_refcount_normal(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) struct ocfs2_xattr_header *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) struct buffer_head *ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) struct ocfs2_cached_dealloc_ctxt *dealloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) struct ocfs2_xattr_value_root *xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) struct ocfs2_extent_tree et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) for (i = 0; i < le16_to_cpu(header->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) xe = &header->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) if (ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) xv = (struct ocfs2_xattr_value_root *)((void *)header +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) le16_to_cpu(xe->xe_name_offset) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) OCFS2_XATTR_SIZE(xe->xe_name_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) vb->vb_xv = xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) ocfs2_init_xattr_value_extent_tree(&et, INODE_CACHE(inode), vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) ret = ocfs2_xattr_value_attach_refcount(inode, xv, &et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) ref_ci, ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) dealloc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) static int ocfs2_xattr_inline_attach_refcount(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) struct buffer_head *fe_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) struct buffer_head *ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) struct ocfs2_cached_dealloc_ctxt *dealloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) struct ocfs2_xattr_header *header = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) (fe_bh->b_data + inode->i_sb->s_blocksize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) le16_to_cpu(di->i_xattr_inline_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) .vb_bh = fe_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) .vb_access = ocfs2_journal_access_di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) return ocfs2_xattr_attach_refcount_normal(inode, &vb, header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) ref_ci, ref_root_bh, dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) struct ocfs2_xattr_tree_value_refcount_para {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) struct ocfs2_caching_info *ref_ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) struct buffer_head *ref_root_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) struct ocfs2_cached_dealloc_ctxt *dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) static int ocfs2_get_xattr_tree_value_root(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) struct ocfs2_xattr_value_root **xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) struct buffer_head **bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) int ret, block_off, name_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) struct ocfs2_xattr_header *xh = bucket_xh(bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) struct ocfs2_xattr_entry *xe = &xh->xh_entries[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) void *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) ret = ocfs2_xattr_bucket_get_name_value(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) bucket_xh(bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) &block_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) &name_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) base = bucket_block(bucket, block_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) *xv = (struct ocfs2_xattr_value_root *)(base + name_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) OCFS2_XATTR_SIZE(xe->xe_name_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) if (bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) *bh = bucket->bu_bhs[block_off];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) * For a given xattr bucket, refcount all the entries which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) * have value stored outside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) static int ocfs2_xattr_bucket_value_refcount(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) struct ocfs2_extent_tree et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) struct ocfs2_xattr_tree_value_refcount_para *ref =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) (struct ocfs2_xattr_tree_value_refcount_para *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) struct ocfs2_xattr_header *xh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) (struct ocfs2_xattr_header *)bucket->bu_bhs[0]->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) .vb_access = ocfs2_journal_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) struct ocfs2_post_refcount refcount = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) .credits = bucket->bu_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) .para = bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) .func = ocfs2_xattr_bucket_post_refcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) struct ocfs2_post_refcount *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) /* We only need post_refcount if we support metaecc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) if (ocfs2_meta_ecc(OCFS2_SB(inode->i_sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) p = &refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) trace_ocfs2_xattr_bucket_value_refcount(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) (unsigned long long)bucket_blkno(bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) le16_to_cpu(xh->xh_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) for (i = 0; i < le16_to_cpu(xh->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) xe = &xh->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) if (ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) ret = ocfs2_get_xattr_tree_value_root(inode->i_sb, bucket, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) &vb.vb_xv, &vb.vb_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) ocfs2_init_xattr_value_extent_tree(&et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) INODE_CACHE(inode), &vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) ret = ocfs2_xattr_value_attach_refcount(inode, vb.vb_xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) &et, ref->ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) ref->ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) ref->dealloc, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) static int ocfs2_refcount_xattr_tree_rec(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) u64 blkno, u32 cpos, u32 len, void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) return ocfs2_iterate_xattr_buckets(inode, blkno, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) ocfs2_xattr_bucket_value_refcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) static int ocfs2_xattr_block_attach_refcount(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) struct buffer_head *blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) struct buffer_head *ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) struct ocfs2_cached_dealloc_ctxt *dealloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) struct ocfs2_xattr_header *header = &xb->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) .vb_bh = blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) .vb_access = ocfs2_journal_access_xb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) ret = ocfs2_xattr_attach_refcount_normal(inode, &vb, header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) ref_ci, ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) struct ocfs2_xattr_tree_value_refcount_para para = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) .ref_ci = ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) .ref_root_bh = ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) .dealloc = dealloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130) ret = ocfs2_iterate_xattr_index_block(inode, blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) ocfs2_refcount_xattr_tree_rec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) ¶);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) int ocfs2_xattr_attach_refcount_tree(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) struct buffer_head *fe_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) struct ocfs2_caching_info *ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) struct buffer_head *ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) struct ocfs2_cached_dealloc_ctxt *dealloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) struct ocfs2_inode_info *oi = OCFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) struct buffer_head *blk_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) ret = ocfs2_xattr_inline_attach_refcount(inode, fe_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) ref_ci, ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) if (!di->i_xattr_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) ret = ocfs2_read_xattr_block(inode, le64_to_cpu(di->i_xattr_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) &blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169) ret = ocfs2_xattr_block_attach_refcount(inode, blk_bh, ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) ref_root_bh, dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) brelse(blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) typedef int (should_xattr_reflinked)(struct ocfs2_xattr_entry *xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) * Store the information we need in xattr reflink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) * old_bh and new_bh are inode bh for the old and new inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) struct ocfs2_xattr_reflink {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) struct inode *old_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) struct inode *new_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) struct buffer_head *old_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) struct buffer_head *new_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) struct ocfs2_caching_info *ref_ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) struct buffer_head *ref_root_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) struct ocfs2_cached_dealloc_ctxt *dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) should_xattr_reflinked *xattr_reflinked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) * Given a xattr header and xe offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) * return the proper xv and the corresponding bh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) * xattr in inode, block and xattr tree have different implementaions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) typedef int (get_xattr_value_root)(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) struct ocfs2_xattr_value_root **xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) struct buffer_head **ret_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) void *para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) * Calculate all the xattr value root metadata stored in this xattr header and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) * credits we need if we create them from the scratch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) * We use get_xattr_value_root so that all types of xattr container can use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) static int ocfs2_value_metas_in_xattr_header(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) int *metas, int *credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) int *num_recs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) get_xattr_value_root *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) struct ocfs2_xattr_value_root *xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) struct ocfs2_xattr_entry *xe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) for (i = 0; i < le16_to_cpu(xh->xh_count); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) xe = &xh->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) if (ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) ret = func(sb, bh, xh, i, &xv, NULL, para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) *metas += le16_to_cpu(xv->xr_list.l_tree_depth) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) le16_to_cpu(xv->xr_list.l_next_free_rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) *credits += ocfs2_calc_extend_credits(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) &def_xv.xv.xr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) * If the value is a tree with depth > 1, We don't go deep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) * to the extent block, so just calculate a maximum record num.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) if (!xv->xr_list.l_tree_depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) *num_recs += le16_to_cpu(xv->xr_list.l_next_free_rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) *num_recs += ocfs2_clusters_for_bytes(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) XATTR_SIZE_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) /* Used by xattr inode and block to return the right xv and buffer_head. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) static int ocfs2_get_xattr_value_root(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) struct ocfs2_xattr_value_root **xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) struct buffer_head **ret_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) struct ocfs2_xattr_entry *xe = &xh->xh_entries[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) *xv = (struct ocfs2_xattr_value_root *)((void *)xh +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) le16_to_cpu(xe->xe_name_offset) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) OCFS2_XATTR_SIZE(xe->xe_name_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) if (ret_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) *ret_bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) * Lock the meta_ac and caculate how much credits we need for reflink xattrs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) * It is only used for inline xattr and xattr block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) static int ocfs2_reflink_lock_xattr_allocators(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) struct buffer_head *ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) int *credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) struct ocfs2_alloc_context **meta_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) int ret, meta_add = 0, num_recs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) struct ocfs2_refcount_block *rb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) (struct ocfs2_refcount_block *)ref_root_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) *credits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) ret = ocfs2_value_metas_in_xattr_header(osb->sb, NULL, xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) &meta_add, credits, &num_recs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) ocfs2_get_xattr_value_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) * We need to add/modify num_recs in refcount tree, so just calculate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) * an approximate number we need for refcount tree change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) * Sometimes we need to split the tree, and after split, half recs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) * will be moved to the new block, and a new block can only provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) * half number of recs. So we multiple new blocks by 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) num_recs = num_recs / ocfs2_refcount_recs_per_rb(osb->sb) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) meta_add += num_recs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) *credits += num_recs + num_recs * OCFS2_EXPAND_REFCOUNT_TREE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) if (le32_to_cpu(rb->rf_flags) & OCFS2_REFCOUNT_TREE_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) *credits += le16_to_cpu(rb->rf_list.l_tree_depth) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) le16_to_cpu(rb->rf_list.l_next_free_rec) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) *credits += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add, meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) * Given a xattr header, reflink all the xattrs in this container.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) * It can be used for inode, block and bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) * NOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) * Before we call this function, the caller has memcpy the xattr in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) * old_xh to the new_xh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) * If args.xattr_reflinked is set, call it to decide whether the xe should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) * be reflinked or not. If not, remove it from the new xattr header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) static int ocfs2_reflink_xattr_header(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) struct ocfs2_xattr_reflink *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) struct buffer_head *old_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) struct buffer_head *new_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) struct ocfs2_xattr_header *new_xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) struct ocfs2_xattr_value_buf *vb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) get_xattr_value_root *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) int ret = 0, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) struct super_block *sb = args->old_inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) struct buffer_head *value_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) struct ocfs2_xattr_entry *xe, *last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) struct ocfs2_xattr_value_root *xv, *new_xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) struct ocfs2_extent_tree data_et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) u32 clusters, cpos, p_cluster, num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) unsigned int ext_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) trace_ocfs2_reflink_xattr_header((unsigned long long)old_bh->b_blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) le16_to_cpu(xh->xh_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) last = &new_xh->xh_entries[le16_to_cpu(new_xh->xh_count)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) for (i = 0, j = 0; i < le16_to_cpu(xh->xh_count); i++, j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) xe = &xh->xh_entries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) if (args->xattr_reflinked && !args->xattr_reflinked(xe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) xe = &new_xh->xh_entries[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) le16_add_cpu(&new_xh->xh_count, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) if (new_xh->xh_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) memmove(xe, xe + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) (void *)last - (void *)xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) memset(last, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) sizeof(struct ocfs2_xattr_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) * We don't want j to increase in the next round since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) * it is already moved ahead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) j--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) if (ocfs2_xattr_is_local(xe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) ret = func(sb, old_bh, xh, i, &xv, NULL, para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) ret = func(sb, new_bh, new_xh, j, &new_xv, &value_bh, para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) * For the xattr which has l_tree_depth = 0, all the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) * recs have already be copied to the new xh with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) * propriate OCFS2_EXT_REFCOUNTED flag we just need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) * increase the refount count int the refcount tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) * For the xattr which has l_tree_depth > 0, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) * to initialize it to the empty default value root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) * and then insert the extents one by one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) if (xv->xr_list.l_tree_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) memcpy(new_xv, &def_xv, OCFS2_XATTR_ROOT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) vb->vb_xv = new_xv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) vb->vb_bh = value_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) ocfs2_init_xattr_value_extent_tree(&data_et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) INODE_CACHE(args->new_inode), vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) clusters = le32_to_cpu(xv->xr_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) cpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) while (cpos < clusters) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) ret = ocfs2_xattr_get_clusters(args->old_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) &p_cluster,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) &num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) &xv->xr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) &ext_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) BUG_ON(!p_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) if (xv->xr_list.l_tree_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) ret = ocfs2_insert_extent(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435) &data_et, cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) ocfs2_clusters_to_blocks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437) args->old_inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) p_cluster),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) num_clusters, ext_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) ret = ocfs2_increase_refcount(handle, args->ref_ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) args->ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) p_cluster, num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) meta_ac, args->dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) cpos += num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464) static int ocfs2_reflink_xattr_inline(struct ocfs2_xattr_reflink *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466) int ret = 0, credits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) struct ocfs2_super *osb = OCFS2_SB(args->old_inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) struct ocfs2_dinode *di = (struct ocfs2_dinode *)args->old_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) int inline_size = le16_to_cpu(di->i_xattr_inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) int header_off = osb->sb->s_blocksize - inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) (args->old_bh->b_data + header_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) struct ocfs2_xattr_header *new_xh = (struct ocfs2_xattr_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) (args->new_bh->b_data + header_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) struct ocfs2_alloc_context *meta_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) struct ocfs2_inode_info *new_oi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) struct ocfs2_dinode *new_di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) .vb_bh = args->new_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) .vb_access = ocfs2_journal_access_di,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) ret = ocfs2_reflink_lock_xattr_allocators(osb, xh, args->ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) &credits, &meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) handle = ocfs2_start_trans(osb, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) ret = ocfs2_journal_access_di(handle, INODE_CACHE(args->new_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499) args->new_bh, OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) memcpy(args->new_bh->b_data + header_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) args->old_bh->b_data + header_off, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) new_di = (struct ocfs2_dinode *)args->new_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) new_di->i_xattr_inline_size = cpu_to_le16(inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) ret = ocfs2_reflink_xattr_header(handle, args, args->old_bh, xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) args->new_bh, new_xh, &vb, meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) ocfs2_get_xattr_value_root, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) new_oi = OCFS2_I(args->new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) * Adjust extent record count to reserve space for extended attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) * Inline data count had been adjusted in ocfs2_duplicate_inline_data().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) if (!(new_oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) !(ocfs2_inode_is_fast_symlink(args->new_inode))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) struct ocfs2_extent_list *el = &new_di->id2.i_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) le16_add_cpu(&el->l_count, -(inline_size /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) sizeof(struct ocfs2_extent_rec)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) spin_lock(&new_oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) new_oi->ip_dyn_features |= OCFS2_HAS_XATTR_FL | OCFS2_INLINE_XATTR_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) new_di->i_dyn_features = cpu_to_le16(new_oi->ip_dyn_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) spin_unlock(&new_oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) ocfs2_journal_dirty(handle, args->new_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) out_commit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) if (meta_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) ocfs2_free_alloc_context(meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) static int ocfs2_create_empty_xattr_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) struct buffer_head *fe_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) struct buffer_head **ret_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) int indexed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) struct ocfs2_xattr_set_ctxt ctxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) memset(&ctxt, 0, sizeof(ctxt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &ctxt.meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) ctxt.handle = ocfs2_start_trans(osb, OCFS2_XATTR_BLOCK_CREATE_CREDITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) if (IS_ERR(ctxt.handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) ret = PTR_ERR(ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) trace_ocfs2_create_empty_xattr_block(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) (unsigned long long)fe_bh->b_blocknr, indexed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) ret = ocfs2_create_xattr_block(inode, fe_bh, &ctxt, indexed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) ret_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576) ocfs2_commit_trans(osb, ctxt.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578) ocfs2_free_alloc_context(ctxt.meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) static int ocfs2_reflink_xattr_block(struct ocfs2_xattr_reflink *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) struct buffer_head *blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) struct buffer_head *new_blk_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586) int ret = 0, credits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) struct ocfs2_inode_info *new_oi = OCFS2_I(args->new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589) struct ocfs2_dinode *new_di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) struct ocfs2_super *osb = OCFS2_SB(args->new_inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) int header_off = offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594) struct ocfs2_xattr_header *xh = &xb->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595) struct ocfs2_xattr_block *new_xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596) (struct ocfs2_xattr_block *)new_blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597) struct ocfs2_xattr_header *new_xh = &new_xb->xb_attrs.xb_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598) struct ocfs2_alloc_context *meta_ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) .vb_bh = new_blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) .vb_access = ocfs2_journal_access_xb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) ret = ocfs2_reflink_lock_xattr_allocators(osb, xh, args->ref_root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) &credits, &meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) /* One more credits in case we need to add xattr flags in new inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) handle = ocfs2_start_trans(osb, credits + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) if (!(new_oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) ret = ocfs2_journal_access_di(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) INODE_CACHE(args->new_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) args->new_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630) ret = ocfs2_journal_access_xb(handle, INODE_CACHE(args->new_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) new_blk_bh, OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) memcpy(new_blk_bh->b_data + header_off, blk_bh->b_data + header_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) osb->sb->s_blocksize - header_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) ret = ocfs2_reflink_xattr_header(handle, args, blk_bh, xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641) new_blk_bh, new_xh, &vb, meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642) ocfs2_get_xattr_value_root, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) ocfs2_journal_dirty(handle, new_blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) if (!(new_oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) new_di = (struct ocfs2_dinode *)args->new_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) spin_lock(&new_oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) new_oi->ip_dyn_features |= OCFS2_HAS_XATTR_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654) new_di->i_dyn_features = cpu_to_le16(new_oi->ip_dyn_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) spin_unlock(&new_oi->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) ocfs2_journal_dirty(handle, args->new_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) out_commit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664) ocfs2_free_alloc_context(meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) struct ocfs2_reflink_xattr_tree_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) struct ocfs2_xattr_reflink *reflink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) struct buffer_head *old_blk_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) struct buffer_head *new_blk_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) struct ocfs2_xattr_bucket *old_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) struct ocfs2_xattr_bucket *new_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677) * NOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678) * We have to handle the case that both old bucket and new bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679) * will call this function to get the right ret_bh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) * So The caller must give us the right bh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) static int ocfs2_get_reflink_xattr_value_root(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) struct ocfs2_xattr_value_root **xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687) struct buffer_head **ret_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690) struct ocfs2_reflink_xattr_tree_args *args =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) (struct ocfs2_reflink_xattr_tree_args *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) struct ocfs2_xattr_bucket *bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) if (bh == args->old_bucket->bu_bhs[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) bucket = args->old_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) bucket = args->new_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) return ocfs2_get_xattr_tree_value_root(sb, bucket, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700) xv, ret_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703) struct ocfs2_value_tree_metas {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) int num_metas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705) int credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) int num_recs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) static int ocfs2_value_tree_metas_in_bucket(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711) struct ocfs2_xattr_header *xh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) struct ocfs2_xattr_value_root **xv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714) struct buffer_head **ret_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) struct ocfs2_xattr_bucket *bucket =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) (struct ocfs2_xattr_bucket *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720) return ocfs2_get_xattr_tree_value_root(sb, bucket, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721) xv, ret_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724) static int ocfs2_calc_value_tree_metas(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725) struct ocfs2_xattr_bucket *bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) struct ocfs2_value_tree_metas *metas =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) (struct ocfs2_value_tree_metas *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) struct ocfs2_xattr_header *xh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) (struct ocfs2_xattr_header *)bucket->bu_bhs[0]->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) /* Add the credits for this bucket first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) metas->credits += bucket->bu_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) return ocfs2_value_metas_in_xattr_header(inode->i_sb, bucket->bu_bhs[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) xh, &metas->num_metas,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) &metas->credits, &metas->num_recs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) ocfs2_value_tree_metas_in_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739) bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) * Given a xattr extent rec starting from blkno and having len clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744) * iterate all the buckets calculate how much metadata we need for reflinking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745) * all the ocfs2_xattr_value_root and lock the allocators accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747) static int ocfs2_lock_reflink_xattr_rec_allocators(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) struct ocfs2_reflink_xattr_tree_args *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) struct ocfs2_extent_tree *xt_et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) u64 blkno, u32 len, int *credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) struct ocfs2_alloc_context **meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) struct ocfs2_alloc_context **data_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754) int ret, num_free_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) struct ocfs2_value_tree_metas metas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756) struct ocfs2_super *osb = OCFS2_SB(args->reflink->old_inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) struct ocfs2_refcount_block *rb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) memset(&metas, 0, sizeof(metas));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) ret = ocfs2_iterate_xattr_buckets(args->reflink->old_inode, blkno, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) ocfs2_calc_value_tree_metas, &metas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6768) *credits = metas.credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6770) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6771) * Calculate we need for refcount tree change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6772) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6773) * We need to add/modify num_recs in refcount tree, so just calculate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6774) * an approximate number we need for refcount tree change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6775) * Sometimes we need to split the tree, and after split, half recs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6776) * will be moved to the new block, and a new block can only provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6777) * half number of recs. So we multiple new blocks by 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6778) * In the end, we have to add credits for modifying the already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6779) * existed refcount block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6781) rb = (struct ocfs2_refcount_block *)args->reflink->ref_root_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6782) metas.num_recs =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6783) (metas.num_recs + ocfs2_refcount_recs_per_rb(osb->sb) - 1) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6784) ocfs2_refcount_recs_per_rb(osb->sb) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6785) metas.num_metas += metas.num_recs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6786) *credits += metas.num_recs +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6787) metas.num_recs * OCFS2_EXPAND_REFCOUNT_TREE_CREDITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6788) if (le32_to_cpu(rb->rf_flags) & OCFS2_REFCOUNT_TREE_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6789) *credits += le16_to_cpu(rb->rf_list.l_tree_depth) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6790) le16_to_cpu(rb->rf_list.l_next_free_rec) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6791) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6792) *credits += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6794) /* count in the xattr tree change. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6795) num_free_extents = ocfs2_num_free_extents(xt_et);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6796) if (num_free_extents < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6797) ret = num_free_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6798) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6799) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6802) if (num_free_extents < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6803) metas.num_metas += ocfs2_extend_meta_needed(xt_et->et_root_el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6805) *credits += ocfs2_calc_extend_credits(osb->sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6806) xt_et->et_root_el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6808) if (metas.num_metas) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6809) ret = ocfs2_reserve_new_metadata_blocks(osb, metas.num_metas,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6810) meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6811) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6812) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6813) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6817) if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6818) ret = ocfs2_reserve_clusters(osb, len, data_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6819) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6820) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6822) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6823) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6824) if (*meta_ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6825) ocfs2_free_alloc_context(*meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6826) *meta_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6830) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6833) static int ocfs2_reflink_xattr_bucket(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6834) u64 blkno, u64 new_blkno, u32 clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6835) u32 *cpos, int num_buckets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6836) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6837) struct ocfs2_alloc_context *data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6838) struct ocfs2_reflink_xattr_tree_args *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6840) int i, j, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6841) struct super_block *sb = args->reflink->old_inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6842) int bpb = args->old_bucket->bu_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6843) struct ocfs2_xattr_value_buf vb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6844) .vb_access = ocfs2_journal_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6845) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6847) for (i = 0; i < num_buckets; i++, blkno += bpb, new_blkno += bpb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6848) ret = ocfs2_read_xattr_bucket(args->old_bucket, blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6849) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6850) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6851) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6854) ret = ocfs2_init_xattr_bucket(args->new_bucket, new_blkno, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6855) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6856) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6857) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6860) ret = ocfs2_xattr_bucket_journal_access(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6861) args->new_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6862) OCFS2_JOURNAL_ACCESS_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6863) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6864) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6865) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6868) for (j = 0; j < bpb; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6869) memcpy(bucket_block(args->new_bucket, j),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6870) bucket_block(args->old_bucket, j),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6871) sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6873) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6874) * Record the start cpos so that we can use it to initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6875) * our xattr tree we also set the xh_num_bucket for the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6876) * bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6877) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6878) if (i == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6879) *cpos = le32_to_cpu(bucket_xh(args->new_bucket)->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6880) xh_entries[0].xe_name_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6881) bucket_xh(args->new_bucket)->xh_num_buckets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6882) cpu_to_le16(num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6885) ocfs2_xattr_bucket_journal_dirty(handle, args->new_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6887) ret = ocfs2_reflink_xattr_header(handle, args->reflink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6888) args->old_bucket->bu_bhs[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6889) bucket_xh(args->old_bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6890) args->new_bucket->bu_bhs[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6891) bucket_xh(args->new_bucket),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6892) &vb, meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6893) ocfs2_get_reflink_xattr_value_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6894) args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6895) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6896) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6897) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6900) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6901) * Re-access and dirty the bucket to calculate metaecc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6902) * Because we may extend the transaction in reflink_xattr_header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6903) * which will let the already accessed block gone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6904) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6905) ret = ocfs2_xattr_bucket_journal_access(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6906) args->new_bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6907) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6908) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6909) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6910) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6913) ocfs2_xattr_bucket_journal_dirty(handle, args->new_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6915) ocfs2_xattr_bucket_relse(args->old_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6916) ocfs2_xattr_bucket_relse(args->new_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6919) ocfs2_xattr_bucket_relse(args->old_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6920) ocfs2_xattr_bucket_relse(args->new_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6921) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6924) static int ocfs2_reflink_xattr_buckets(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6925) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6926) struct ocfs2_reflink_xattr_tree_args *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6927) struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6928) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6929) struct ocfs2_alloc_context *data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6930) u64 blkno, u32 cpos, u32 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6932) int ret, first_inserted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6933) u32 p_cluster, num_clusters, reflink_cpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6934) u64 new_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6935) unsigned int num_buckets, reflink_buckets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6936) unsigned int bpc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6937) ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6939) ret = ocfs2_read_xattr_bucket(args->old_bucket, blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6940) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6941) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6942) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6944) num_buckets = le16_to_cpu(bucket_xh(args->old_bucket)->xh_num_buckets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6945) ocfs2_xattr_bucket_relse(args->old_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6947) while (len && num_buckets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6948) ret = ocfs2_claim_clusters(handle, data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6949) 1, &p_cluster, &num_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6950) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6951) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6952) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6955) new_blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6956) reflink_buckets = min(num_buckets, bpc * num_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6958) ret = ocfs2_reflink_xattr_bucket(handle, blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6959) new_blkno, num_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6960) &reflink_cpos, reflink_buckets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6961) meta_ac, data_ac, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6962) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6963) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6964) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6967) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6968) * For the 1st allocated cluster, we make it use the same cpos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6969) * so that the xattr tree looks the same as the original one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6970) * in the most case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6971) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6972) if (!first_inserted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6973) reflink_cpos = cpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6974) first_inserted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6976) ret = ocfs2_insert_extent(handle, et, reflink_cpos, new_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6977) num_clusters, 0, meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6978) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6979) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6981) trace_ocfs2_reflink_xattr_buckets((unsigned long long)new_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6982) num_clusters, reflink_cpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6984) len -= num_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6985) blkno += ocfs2_clusters_to_blocks(inode->i_sb, num_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6986) num_buckets -= reflink_buckets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6988) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6989) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6992) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6993) * Create the same xattr extent record in the new inode's xattr tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6995) static int ocfs2_reflink_xattr_rec(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6996) struct buffer_head *root_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6997) u64 blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6998) u32 cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6999) u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7000) void *para)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7002) int ret, credits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7003) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7004) struct ocfs2_reflink_xattr_tree_args *args =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7005) (struct ocfs2_reflink_xattr_tree_args *)para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7006) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7007) struct ocfs2_alloc_context *meta_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7008) struct ocfs2_alloc_context *data_ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7009) struct ocfs2_extent_tree et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7011) trace_ocfs2_reflink_xattr_rec((unsigned long long)blkno, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7013) ocfs2_init_xattr_tree_extent_tree(&et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7014) INODE_CACHE(args->reflink->new_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7015) args->new_blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7017) ret = ocfs2_lock_reflink_xattr_rec_allocators(args, &et, blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7018) len, &credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7019) &meta_ac, &data_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7020) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7021) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7022) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7025) handle = ocfs2_start_trans(osb, credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7026) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7027) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7028) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7029) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7032) ret = ocfs2_reflink_xattr_buckets(handle, inode, args, &et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7033) meta_ac, data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7034) blkno, cpos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7035) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7036) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7038) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7040) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7041) if (meta_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7042) ocfs2_free_alloc_context(meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7043) if (data_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7044) ocfs2_free_alloc_context(data_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7045) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7048) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7049) * Create reflinked xattr buckets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7050) * We will add bucket one by one, and refcount all the xattrs in the bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7051) * if they are stored outside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7052) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7053) static int ocfs2_reflink_xattr_tree(struct ocfs2_xattr_reflink *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7054) struct buffer_head *blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7055) struct buffer_head *new_blk_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7057) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7058) struct ocfs2_reflink_xattr_tree_args para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7060) memset(¶, 0, sizeof(para));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7061) para.reflink = args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7062) para.old_blk_bh = blk_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7063) para.new_blk_bh = new_blk_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7065) para.old_bucket = ocfs2_xattr_bucket_new(args->old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7066) if (!para.old_bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7067) mlog_errno(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7068) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7071) para.new_bucket = ocfs2_xattr_bucket_new(args->new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7072) if (!para.new_bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7073) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7074) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7075) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7078) ret = ocfs2_iterate_xattr_index_block(args->old_inode, blk_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7079) ocfs2_reflink_xattr_rec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7080) ¶);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7081) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7082) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7084) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7085) ocfs2_xattr_bucket_free(para.old_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7086) ocfs2_xattr_bucket_free(para.new_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7087) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7090) static int ocfs2_reflink_xattr_in_block(struct ocfs2_xattr_reflink *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7091) struct buffer_head *blk_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7093) int ret, indexed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7094) struct buffer_head *new_blk_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7095) struct ocfs2_xattr_block *xb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7096) (struct ocfs2_xattr_block *)blk_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7099) if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7100) indexed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7102) ret = ocfs2_create_empty_xattr_block(args->new_inode, args->new_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7103) &new_blk_bh, indexed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7104) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7105) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7106) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7109) if (!indexed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7110) ret = ocfs2_reflink_xattr_block(args, blk_bh, new_blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7111) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7112) ret = ocfs2_reflink_xattr_tree(args, blk_bh, new_blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7113) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7114) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7116) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7117) brelse(new_blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7118) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7121) static int ocfs2_reflink_xattr_no_security(struct ocfs2_xattr_entry *xe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7123) int type = ocfs2_xattr_get_type(xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7125) return type != OCFS2_XATTR_INDEX_SECURITY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7126) type != OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7127) type != OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7130) int ocfs2_reflink_xattrs(struct inode *old_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7131) struct buffer_head *old_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7132) struct inode *new_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7133) struct buffer_head *new_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7134) bool preserve_security)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7136) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7137) struct ocfs2_xattr_reflink args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7138) struct ocfs2_inode_info *oi = OCFS2_I(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7139) struct ocfs2_dinode *di = (struct ocfs2_dinode *)old_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7140) struct buffer_head *blk_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7141) struct ocfs2_cached_dealloc_ctxt dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7142) struct ocfs2_refcount_tree *ref_tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7143) struct buffer_head *ref_root_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7145) ret = ocfs2_lock_refcount_tree(OCFS2_SB(old_inode->i_sb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7146) le64_to_cpu(di->i_refcount_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7147) 1, &ref_tree, &ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7148) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7149) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7150) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7153) ocfs2_init_dealloc_ctxt(&dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7155) args.old_inode = old_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7156) args.new_inode = new_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7157) args.old_bh = old_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7158) args.new_bh = new_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7159) args.ref_ci = &ref_tree->rf_ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7160) args.ref_root_bh = ref_root_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7161) args.dealloc = &dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7162) if (preserve_security)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7163) args.xattr_reflinked = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7164) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7165) args.xattr_reflinked = ocfs2_reflink_xattr_no_security;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7167) if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7168) ret = ocfs2_reflink_xattr_inline(&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7169) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7170) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7171) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7175) if (!di->i_xattr_loc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7176) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7178) ret = ocfs2_read_xattr_block(old_inode, le64_to_cpu(di->i_xattr_loc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7179) &blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7180) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7181) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7182) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7185) ret = ocfs2_reflink_xattr_in_block(&args, blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7186) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7187) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7189) brelse(blk_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7191) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7192) ocfs2_unlock_refcount_tree(OCFS2_SB(old_inode->i_sb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7193) ref_tree, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7194) brelse(ref_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7196) if (ocfs2_dealloc_has_cluster(&dealloc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7197) ocfs2_schedule_truncate_log_flush(OCFS2_SB(old_inode->i_sb), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7198) ocfs2_run_deallocs(OCFS2_SB(old_inode->i_sb), &dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7201) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7202) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7206) * Initialize security and acl for a already created inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7207) * Used for reflink a non-preserve-security file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7208) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7209) * It uses common api like ocfs2_xattr_set, so the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7210) * must not hold any lock expect i_mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7212) int ocfs2_init_security_and_acl(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7213) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7214) const struct qstr *qstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7216) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7217) struct buffer_head *dir_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7219) ret = ocfs2_init_security_get(inode, dir, qstr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7220) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7221) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7222) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7225) ret = ocfs2_inode_lock(dir, &dir_bh, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7226) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7227) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7228) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7230) ret = ocfs2_init_acl(NULL, inode, dir, NULL, dir_bh, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7231) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7232) mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7234) ocfs2_inode_unlock(dir, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7235) brelse(dir_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7236) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7237) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7241) * 'security' attributes support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7243) static int ocfs2_xattr_security_get(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7244) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7245) const char *name, void *buffer, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7246) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7248) return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_SECURITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7249) name, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7252) static int ocfs2_xattr_security_set(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7253) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7254) const char *name, const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7255) size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7257) return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7258) name, value, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7261) static int ocfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7262) void *fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7264) const struct xattr *xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7265) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7267) for (xattr = xattr_array; xattr->name != NULL; xattr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7268) err = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7269) xattr->name, xattr->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7270) xattr->value_len, XATTR_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7271) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7274) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7277) int ocfs2_init_security_get(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7278) struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7279) const struct qstr *qstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7280) struct ocfs2_security_xattr_info *si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7282) /* check whether ocfs2 support feature xattr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7283) if (!ocfs2_supports_xattr(OCFS2_SB(dir->i_sb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7284) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7285) if (si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7286) return security_old_inode_init_security(inode, dir, qstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7287) &si->name, &si->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7288) &si->value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7290) return security_inode_init_security(inode, dir, qstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7291) &ocfs2_initxattrs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7294) int ocfs2_init_security_set(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7295) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7296) struct buffer_head *di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7297) struct ocfs2_security_xattr_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7298) struct ocfs2_alloc_context *xattr_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7299) struct ocfs2_alloc_context *data_ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7301) return ocfs2_xattr_set_handle(handle, inode, di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7302) OCFS2_XATTR_INDEX_SECURITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7303) si->name, si->value, si->value_len, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7304) xattr_ac, data_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7307) const struct xattr_handler ocfs2_xattr_security_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7308) .prefix = XATTR_SECURITY_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7309) .get = ocfs2_xattr_security_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7310) .set = ocfs2_xattr_security_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7311) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7314) * 'trusted' attributes support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7316) static int ocfs2_xattr_trusted_get(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7317) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7318) const char *name, void *buffer, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7319) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7321) return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7322) name, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7325) static int ocfs2_xattr_trusted_set(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7326) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7327) const char *name, const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7328) size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7330) return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7331) name, value, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7334) const struct xattr_handler ocfs2_xattr_trusted_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7335) .prefix = XATTR_TRUSTED_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7336) .get = ocfs2_xattr_trusted_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7337) .set = ocfs2_xattr_trusted_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7338) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7340) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7341) * 'user' attributes support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7342) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7343) static int ocfs2_xattr_user_get(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7344) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7345) const char *name, void *buffer, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7346) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7348) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7350) if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7351) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7352) return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7353) buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7356) static int ocfs2_xattr_user_set(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7357) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7358) const char *name, const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7359) size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7361) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7363) if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7364) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7366) return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7367) name, value, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7370) const struct xattr_handler ocfs2_xattr_user_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7371) .prefix = XATTR_USER_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7372) .get = ocfs2_xattr_user_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7373) .set = ocfs2_xattr_user_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7374) };