^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/gfs2_ondisk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "gfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "glock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "meta_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "quota.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "rgrp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * ea_calc_size - returns the acutal number of bytes the request will take up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * (not counting any unstuffed data blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @sdp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * @er:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * @size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Returns: 1 if the EA should be stuffed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int ea_calc_size(struct gfs2_sbd *sdp, unsigned int nsize, size_t dsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned int *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned int jbsize = sdp->sd_jbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* Stuffed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *size = ALIGN(sizeof(struct gfs2_ea_header) + nsize + dsize, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (*size <= jbsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* Unstuffed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *size = ALIGN(sizeof(struct gfs2_ea_header) + nsize +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) (sizeof(__be64) * DIV_ROUND_UP(dsize, jbsize)), 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int ea_check_size(struct gfs2_sbd *sdp, unsigned int nsize, size_t dsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (dsize > GFS2_EA_MAX_DATA_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ea_calc_size(sdp, nsize, dsize, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* This can only happen with 512 byte blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (size > sdp->sd_jbsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct gfs2_ea_header *ea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct gfs2_ea_header *prev, void *private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ea_call_t ea_call, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct gfs2_ea_header *ea, *prev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_EA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (!GFS2_EA_REC_LEN(ea))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!(bh->b_data <= (char *)ea && (char *)GFS2_EA2NEXT(ea) <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) bh->b_data + bh->b_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!GFS2_EATYPE_VALID(ea->ea_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) error = ea_call(ip, bh, ea, prev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (GFS2_EA_IS_LAST(ea)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if ((char *)GFS2_EA2NEXT(ea) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) bh->b_data + bh->b_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) gfs2_consist_inode(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct buffer_head *bh, *eabh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) __be64 *eablk, *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT, 0, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!(ip->i_diskflags & GFS2_DIF_EA_INDIRECT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) error = ea_foreach_i(ip, bh, ea_call, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_IN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto out;
^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) eablk = (__be64 *)(bh->b_data + sizeof(struct gfs2_meta_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) end = eablk + GFS2_SB(&ip->i_inode)->sd_inptrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) for (; eablk < end; eablk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (!*eablk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) bn = be64_to_cpu(*eablk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) error = gfs2_meta_read(ip->i_gl, bn, DIO_WAIT, 0, &eabh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) error = ea_foreach_i(ip, eabh, ea_call, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) brelse(eabh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct ea_find {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) size_t namel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct gfs2_ea_location *ef_el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int ea_find_i(struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct gfs2_ea_header *ea, struct gfs2_ea_header *prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct ea_find *ef = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (ea->ea_type == GFS2_EATYPE_UNUSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (ea->ea_type == ef->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (ea->ea_name_len == ef->namel &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) !memcmp(GFS2_EA2NAME(ea), ef->name, ea->ea_name_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct gfs2_ea_location *el = ef->ef_el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) el->el_bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) el->el_ea = ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) el->el_prev = prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return 1;
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int gfs2_ea_find(struct gfs2_inode *ip, int type, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct gfs2_ea_location *el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct ea_find ef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ef.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ef.name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ef.namel = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ef.ef_el = el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) memset(el, 0, sizeof(struct gfs2_ea_location));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) error = ea_foreach(ip, ea_find_i, &ef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (error > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^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) * ea_dealloc_unstuffed -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * @ip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * @bh:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * @ea:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * @prev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * @private:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * Take advantage of the fact that all unstuffed blocks are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * allocated from the same RG. But watch, this may not always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * be true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct gfs2_ea_header *ea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct gfs2_ea_header *prev, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int *leave = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct gfs2_rgrpd *rgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct gfs2_holder rg_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) __be64 *dataptrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) u64 bn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) u64 bstart = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) unsigned int blen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) unsigned int blks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) unsigned int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (GFS2_EA_IS_STUFFED(ea))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) dataptrs = GFS2_EA2DATAPTRS(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (*dataptrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) blks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) bn = be64_to_cpu(*dataptrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (!blks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) rgd = gfs2_blk2rgrpd(sdp, bn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!rgd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) gfs2_consist_inode(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rg_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) error = gfs2_trans_begin(sdp, rgd->rd_length + RES_DINODE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) RES_EATTR + RES_STATFS + RES_QUOTA, blks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) gfs2_trans_add_meta(ip->i_gl, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) dataptrs = GFS2_EA2DATAPTRS(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (!*dataptrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) bn = be64_to_cpu(*dataptrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (bstart + blen == bn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) blen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (bstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) gfs2_free_meta(ip, rgd, bstart, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) bstart = bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) blen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) *dataptrs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) gfs2_add_inode_blocks(&ip->i_inode, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (bstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) gfs2_free_meta(ip, rgd, bstart, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (prev && !leave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) prev->ea_rec_len = cpu_to_be32(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (GFS2_EA_IS_LAST(ea))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) prev->ea_flags |= GFS2_EAFLAG_LAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ea->ea_type = GFS2_EATYPE_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ea->ea_num_ptrs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ip->i_inode.i_ctime = current_time(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) __mark_inode_dirty(&ip->i_inode, I_DIRTY_DATASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) out_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) gfs2_glock_dq_uninit(&rg_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct gfs2_ea_header *ea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct gfs2_ea_header *prev, int leave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) error = gfs2_rindex_update(GFS2_SB(&ip->i_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) goto out_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) error = ea_dealloc_unstuffed(ip, bh, ea, prev, (leave) ? &error : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) gfs2_quota_unhold(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) out_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return error;
^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) struct ea_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct gfs2_ea_request *ei_er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) unsigned int ei_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct gfs2_ea_header *ea, struct gfs2_ea_header *prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct ea_list *ei = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct gfs2_ea_request *er = ei->ei_er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) unsigned int ea_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) char *prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) unsigned int l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (ea->ea_type == GFS2_EATYPE_UNUSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) switch (ea->ea_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) case GFS2_EATYPE_USR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) prefix = "user.";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) l = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) case GFS2_EATYPE_SYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) prefix = "system.";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) l = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) case GFS2_EATYPE_SECURITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) prefix = "security.";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) l = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ea_size = l + ea->ea_name_len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (er->er_data_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (ei->ei_size + ea_size > er->er_data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) memcpy(er->er_data + ei->ei_size, prefix, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) memcpy(er->er_data + ei->ei_size + l, GFS2_EA2NAME(ea),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ea->ea_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) er->er_data[ei->ei_size + ea_size - 1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ei->ei_size += ea_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return 0;
^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) * gfs2_listxattr - List gfs2 extended attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * @dentry: The dentry whose inode we are interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * @buffer: The buffer to write the results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * @size: The size of the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * Returns: actual size of data on success, -errno on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct gfs2_inode *ip = GFS2_I(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct gfs2_ea_request er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct gfs2_holder i_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) memset(&er, 0, sizeof(struct gfs2_ea_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) er.er_data = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) er.er_data_len = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (ip->i_eattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct ea_list ei = { .ei_er = &er, .ei_size = 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) error = ea_foreach(ip, ea_list_i, &ei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) error = ei.ei_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) gfs2_glock_dq_uninit(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * ea_iter_unstuffed - copies the unstuffed xattr data to/from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * request buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * @ip: The GFS2 inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * @ea: The extended attribute header structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * @din: The data to be copied in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * @dout: The data to be copied out (one of din,dout will be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * Returns: errno
^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 int gfs2_iter_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) const char *din, char *dout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct buffer_head **bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) unsigned int amount = GFS2_EA_DATA_LEN(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) __be64 *dataptrs = GFS2_EA2DATAPTRS(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) unsigned int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) unsigned char *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) unsigned cp_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) for (x = 0; x < nptrs; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) bh + x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) while (x--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) brelse(bh[x]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) dataptrs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) for (x = 0; x < nptrs; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) error = gfs2_meta_wait(sdp, bh[x]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) for (; x < nptrs; x++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) brelse(bh[x]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) for (; x < nptrs; x++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) brelse(bh[x]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) goto out;
^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) pos = bh[x]->b_data + sizeof(struct gfs2_meta_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) cp_size = (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (dout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) memcpy(dout, pos, cp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dout += sdp->sd_jbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (din) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) gfs2_trans_add_meta(ip->i_gl, bh[x]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) memcpy(pos, din, cp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) din += sdp->sd_jbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) amount -= sdp->sd_jbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) brelse(bh[x]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) kfree(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) char *data, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) size_t len = GFS2_EA_DATA_LEN(el->el_ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (len > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (GFS2_EA_IS_STUFFED(el->el_ea)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) memcpy(data, GFS2_EA2DATA(el->el_ea), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ret = gfs2_iter_unstuffed(ip, el->el_ea, NULL, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) int gfs2_xattr_acl_get(struct gfs2_inode *ip, const char *name, char **ppdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct gfs2_ea_location el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) error = gfs2_ea_find(ip, GFS2_EATYPE_SYS, name, &el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (!el.el_ea)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (!GFS2_EA_DATA_LEN(el.el_ea))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) len = GFS2_EA_DATA_LEN(el.el_ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) data = kmalloc(len, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) error = gfs2_ea_get_copy(ip, &el, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) *ppdata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) brelse(el.el_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * gfs2_xattr_get - Get a GFS2 extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * @inode: The inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * @name: The name of the extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * @buffer: The buffer to write the result into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * @size: The size of the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * @type: The type of extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * Returns: actual size of data on success, -errno on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static int __gfs2_xattr_get(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) void *buffer, size_t size, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct gfs2_ea_location el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (!ip->i_eattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (strlen(name) > GFS2_EA_MAX_NAME_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) error = gfs2_ea_find(ip, type, name, &el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (!el.el_ea)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) error = gfs2_ea_get_copy(ip, &el, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) error = GFS2_EA_DATA_LEN(el.el_ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) brelse(el.el_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static int gfs2_xattr_get(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) const char *name, void *buffer, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* During lookup, SELinux calls this function with the glock locked. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) gfs2_holder_mark_uninitialized(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ret = __gfs2_xattr_get(inode, name, buffer, size, handler->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (gfs2_holder_initialized(&gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * ea_alloc_blk - allocates a new block for extended attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * @ip: A pointer to the inode that's getting extended attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * @bhp: Pointer to pointer to a struct buffer_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct gfs2_ea_header *ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) unsigned int n = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) u64 block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) gfs2_trans_remove_revoke(sdp, block, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) *bhp = gfs2_meta_new(ip->i_gl, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) gfs2_trans_add_meta(ip->i_gl, *bhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) gfs2_buffer_clear_tail(*bhp, sizeof(struct gfs2_meta_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) ea = GFS2_EA_BH2FIRST(*bhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) ea->ea_rec_len = cpu_to_be32(sdp->sd_jbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) ea->ea_type = GFS2_EATYPE_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) ea->ea_flags = GFS2_EAFLAG_LAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) ea->ea_num_ptrs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) gfs2_add_inode_blocks(&ip->i_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return 0;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * ea_write - writes the request info to an ea, creating new blocks if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * @ip: inode that is being modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * @ea: the location of the new ea in a block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * @er: the write request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * Note: does not update ea_rec_len or the GFS2_EAFLAG_LAST bin of ea_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * returns : errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) struct gfs2_ea_request *er)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) ea->ea_data_len = cpu_to_be32(er->er_data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ea->ea_name_len = er->er_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) ea->ea_type = er->er_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) ea->__pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) memcpy(GFS2_EA2NAME(ea), er->er_name, er->er_name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (GFS2_EAREQ_SIZE_STUFFED(er) <= sdp->sd_jbsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ea->ea_num_ptrs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) memcpy(GFS2_EA2DATA(ea), er->er_data, er->er_data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) __be64 *dataptr = GFS2_EA2DATAPTRS(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) const char *data = er->er_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) unsigned int data_len = er->er_data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) unsigned int copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) unsigned int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) ea->ea_num_ptrs = DIV_ROUND_UP(er->er_data_len, sdp->sd_jbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) for (x = 0; x < ea->ea_num_ptrs; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) u64 block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) int mh_size = sizeof(struct gfs2_meta_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) unsigned int n = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) gfs2_trans_remove_revoke(sdp, block, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) bh = gfs2_meta_new(ip->i_gl, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) gfs2_trans_add_meta(ip->i_gl, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) gfs2_add_inode_blocks(&ip->i_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) copy = data_len > sdp->sd_jbsize ? sdp->sd_jbsize :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) memcpy(bh->b_data + mh_size, data, copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (copy < sdp->sd_jbsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) memset(bh->b_data + mh_size + copy, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) sdp->sd_jbsize - copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) *dataptr++ = cpu_to_be64(bh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) data += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) data_len -= copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) gfs2_assert_withdraw(sdp, !data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) typedef int (*ea_skeleton_call_t) (struct gfs2_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) struct gfs2_ea_request *er, void *private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) unsigned int blks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) ea_skeleton_call_t skeleton_call, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) struct gfs2_alloc_parms ap = { .target = blks };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) error = gfs2_rindex_update(GFS2_SB(&ip->i_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) error = gfs2_quota_lock_check(ip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) error = gfs2_inplace_reserve(ip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) goto out_gunlock_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) error = gfs2_trans_begin(GFS2_SB(&ip->i_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) blks + gfs2_rg_blocks(ip, blks) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) RES_DINODE + RES_STATFS + RES_QUOTA, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) goto out_ipres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) error = skeleton_call(ip, er, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) ip->i_inode.i_ctime = current_time(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) __mark_inode_dirty(&ip->i_inode, I_DIRTY_DATASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) out_end_trans:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) gfs2_trans_end(GFS2_SB(&ip->i_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) out_ipres:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) gfs2_inplace_release(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) out_gunlock_q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) gfs2_quota_unlock(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return error;
^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 ea_init_i(struct gfs2_inode *ip, struct gfs2_ea_request *er,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) error = ea_alloc_blk(ip, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) ip->i_eattr = bh->b_blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) error = ea_write(ip, GFS2_EA_BH2FIRST(bh), er);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * ea_init - initializes a new eattr block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) * @ip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) * @er:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) static int ea_init(struct gfs2_inode *ip, int type, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) const void *data, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct gfs2_ea_request er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) unsigned int jbsize = GFS2_SB(&ip->i_inode)->sd_jbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) unsigned int blks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) er.er_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) er.er_name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) er.er_name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) er.er_data = (void *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) er.er_data_len = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (GFS2_EAREQ_SIZE_STUFFED(&er) > jbsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) blks += DIV_ROUND_UP(er.er_data_len, jbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) return ea_alloc_skeleton(ip, &er, blks, ea_init_i, NULL);
^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 struct gfs2_ea_header *ea_split_ea(struct gfs2_ea_header *ea)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) u32 ea_size = GFS2_EA_SIZE(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct gfs2_ea_header *new = (struct gfs2_ea_header *)((char *)ea +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) ea_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) u32 new_size = GFS2_EA_REC_LEN(ea) - ea_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) int last = ea->ea_flags & GFS2_EAFLAG_LAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) ea->ea_rec_len = cpu_to_be32(ea_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) ea->ea_flags ^= last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) new->ea_rec_len = cpu_to_be32(new_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) new->ea_flags = last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) static void ea_set_remove_stuffed(struct gfs2_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct gfs2_ea_location *el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct gfs2_ea_header *ea = el->el_ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) struct gfs2_ea_header *prev = el->el_prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) gfs2_trans_add_meta(ip->i_gl, el->el_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (!prev || !GFS2_EA_IS_STUFFED(ea)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) ea->ea_type = GFS2_EATYPE_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) } else if (GFS2_EA2NEXT(prev) != ea) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) prev = GFS2_EA2NEXT(prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), GFS2_EA2NEXT(prev) == ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) prev->ea_rec_len = cpu_to_be32(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (GFS2_EA_IS_LAST(ea))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) prev->ea_flags |= GFS2_EAFLAG_LAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) struct ea_set {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) int ea_split;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct gfs2_ea_request *es_er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct gfs2_ea_location *es_el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct buffer_head *es_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) struct gfs2_ea_header *es_ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) struct gfs2_ea_header *ea, struct ea_set *es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) struct gfs2_ea_request *er = es->es_er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + 2 * RES_EATTR, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) gfs2_trans_add_meta(ip->i_gl, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (es->ea_split)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) ea = ea_split_ea(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) ea_write(ip, ea, er);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (es->es_el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) ea_set_remove_stuffed(ip, es->es_el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) ip->i_inode.i_ctime = current_time(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) __mark_inode_dirty(&ip->i_inode, I_DIRTY_DATASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) gfs2_trans_end(GFS2_SB(&ip->i_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) static int ea_set_simple_alloc(struct gfs2_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) struct gfs2_ea_request *er, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) struct ea_set *es = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) struct gfs2_ea_header *ea = es->es_ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) gfs2_trans_add_meta(ip->i_gl, es->es_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (es->ea_split)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) ea = ea_split_ea(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) error = ea_write(ip, ea, er);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (es->es_el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) ea_set_remove_stuffed(ip, es->es_el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) struct gfs2_ea_header *ea, struct gfs2_ea_header *prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) struct ea_set *es = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) int stuffed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) stuffed = ea_calc_size(GFS2_SB(&ip->i_inode), es->es_er->er_name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) es->es_er->er_data_len, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (ea->ea_type == GFS2_EATYPE_UNUSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) if (GFS2_EA_REC_LEN(ea) < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (!GFS2_EA_IS_STUFFED(ea)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) error = ea_remove_unstuffed(ip, bh, ea, prev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) es->ea_split = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) } else if (GFS2_EA_REC_LEN(ea) - GFS2_EA_SIZE(ea) >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) es->ea_split = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (stuffed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) error = ea_set_simple_noalloc(ip, bh, ea, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) unsigned int blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) es->es_bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) es->es_ea = ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) blks = 2 + DIV_ROUND_UP(es->es_er->er_data_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) GFS2_SB(&ip->i_inode)->sd_jbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) error = ea_alloc_skeleton(ip, es->es_er, blks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) ea_set_simple_alloc, es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) struct buffer_head *indbh, *newbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) __be64 *eablk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) int mh_size = sizeof(struct gfs2_meta_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (ip->i_diskflags & GFS2_DIF_EA_INDIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) __be64 *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) &indbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) if (gfs2_metatype_check(sdp, indbh, GFS2_METATYPE_IN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) eablk = (__be64 *)(indbh->b_data + mh_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) end = eablk + sdp->sd_inptrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) for (; eablk < end; eablk++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (!*eablk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if (eablk == end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) error = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) gfs2_trans_add_meta(ip->i_gl, indbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) u64 blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) unsigned int n = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) error = gfs2_alloc_blocks(ip, &blk, &n, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) gfs2_trans_remove_revoke(sdp, blk, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) indbh = gfs2_meta_new(ip->i_gl, blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) gfs2_trans_add_meta(ip->i_gl, indbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) gfs2_buffer_clear_tail(indbh, mh_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) eablk = (__be64 *)(indbh->b_data + mh_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) *eablk = cpu_to_be64(ip->i_eattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) ip->i_eattr = blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) ip->i_diskflags |= GFS2_DIF_EA_INDIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) gfs2_add_inode_blocks(&ip->i_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) eablk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) error = ea_alloc_blk(ip, &newbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) *eablk = cpu_to_be64((u64)newbh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) error = ea_write(ip, GFS2_EA_BH2FIRST(newbh), er);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) brelse(newbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) if (private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) ea_set_remove_stuffed(ip, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) brelse(indbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) static int ea_set_i(struct gfs2_inode *ip, int type, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) const void *value, size_t size, struct gfs2_ea_location *el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) struct gfs2_ea_request er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) struct ea_set es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) unsigned int blks = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) er.er_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) er.er_name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) er.er_data = (void *)value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) er.er_name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) er.er_data_len = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) memset(&es, 0, sizeof(struct ea_set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) es.es_er = &er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) es.es_el = el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) error = ea_foreach(ip, ea_set_simple, &es);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (error > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) if (!(ip->i_diskflags & GFS2_DIF_EA_INDIRECT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) blks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) if (GFS2_EAREQ_SIZE_STUFFED(&er) > GFS2_SB(&ip->i_inode)->sd_jbsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) blks += DIV_ROUND_UP(er.er_data_len, GFS2_SB(&ip->i_inode)->sd_jbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) return ea_alloc_skeleton(ip, &er, blks, ea_set_block, el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static int ea_set_remove_unstuffed(struct gfs2_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) struct gfs2_ea_location *el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (el->el_prev && GFS2_EA2NEXT(el->el_prev) != el->el_ea) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) el->el_prev = GFS2_EA2NEXT(el->el_prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) gfs2_assert_withdraw(GFS2_SB(&ip->i_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) GFS2_EA2NEXT(el->el_prev) == el->el_ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) return ea_remove_unstuffed(ip, el->el_bh, el->el_ea, el->el_prev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) struct gfs2_ea_header *ea = el->el_ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) struct gfs2_ea_header *prev = el->el_prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) gfs2_trans_add_meta(ip->i_gl, el->el_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if (prev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) prev->ea_rec_len = cpu_to_be32(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) if (GFS2_EA_IS_LAST(ea))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) prev->ea_flags |= GFS2_EAFLAG_LAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) ea->ea_type = GFS2_EATYPE_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) ip->i_inode.i_ctime = current_time(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) __mark_inode_dirty(&ip->i_inode, I_DIRTY_DATASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) gfs2_trans_end(GFS2_SB(&ip->i_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) * gfs2_xattr_remove - Remove a GFS2 extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) * @ip: The inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) * @type: The type of the extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) * @name: The name of the extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) * This is not called directly by the VFS since we use the (common)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) * scheme of making a "set with NULL data" mean a remove request. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) * that this is different from a set with zero length data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) * Returns: 0, or errno on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static int gfs2_xattr_remove(struct gfs2_inode *ip, int type, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) struct gfs2_ea_location el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) if (!ip->i_eattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) error = gfs2_ea_find(ip, type, name, &el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (!el.el_ea)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) if (GFS2_EA_IS_STUFFED(el.el_ea))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) error = ea_remove_stuffed(ip, &el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) error = ea_remove_unstuffed(ip, el.el_bh, el.el_ea, el.el_prev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) brelse(el.el_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) * __gfs2_xattr_set - Set (or remove) a GFS2 extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * @ip: The inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) * @name: The name of the extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) * @value: The value of the extended attribute (NULL for remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) * @size: The size of the @value argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) * @flags: Create or Replace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) * @type: The type of the extended attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) * See gfs2_xattr_remove() for details of the removal of xattrs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) * Returns: 0 or errno on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) int __gfs2_xattr_set(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) const void *value, size_t size, int flags, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) struct gfs2_sbd *sdp = GFS2_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) struct gfs2_ea_location el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) unsigned int namel = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) if (namel > GFS2_EA_MAX_NAME_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) if (value == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) error = gfs2_xattr_remove(ip, type, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (error == -ENODATA && !(flags & XATTR_REPLACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) if (ea_check_size(sdp, namel, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (!ip->i_eattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) if (flags & XATTR_REPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) return ea_init(ip, type, name, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) error = gfs2_ea_find(ip, type, name, &el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) if (el.el_ea) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) if (ip->i_diskflags & GFS2_DIF_APPENDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) brelse(el.el_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return -EPERM;
^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) error = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) if (!(flags & XATTR_CREATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) int unstuffed = !GFS2_EA_IS_STUFFED(el.el_ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) error = ea_set_i(ip, type, name, value, size, &el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (!error && unstuffed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) ea_set_remove_unstuffed(ip, &el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) brelse(el.el_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) error = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (!(flags & XATTR_REPLACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) error = ea_set_i(ip, type, name, value, size, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) static int gfs2_xattr_set(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) const char *name, const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) ret = gfs2_qa_get(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) /* May be called from gfs_setattr with the glock locked. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) if (WARN_ON_ONCE(ip->i_gl->gl_state != LM_ST_EXCLUSIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) gfs2_holder_mark_uninitialized(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) ret = __gfs2_xattr_set(inode, name, value, size, flags, handler->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) if (gfs2_holder_initialized(&gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) gfs2_qa_put(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) static int ea_dealloc_indirect(struct gfs2_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) struct gfs2_rgrp_list rlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) struct gfs2_rgrpd *rgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) struct buffer_head *indbh, *dibh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) __be64 *eablk, *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) unsigned int rg_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) u64 bstart = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) unsigned int blen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) unsigned int blks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) unsigned int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) memset(&rlist, 0, sizeof(struct gfs2_rgrp_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT, 0, &indbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) if (gfs2_metatype_check(sdp, indbh, GFS2_METATYPE_IN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) goto out;
^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) eablk = (__be64 *)(indbh->b_data + sizeof(struct gfs2_meta_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) end = eablk + sdp->sd_inptrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) for (; eablk < end; eablk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) u64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) if (!*eablk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) bn = be64_to_cpu(*eablk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) if (bstart + blen == bn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) blen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) if (bstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) gfs2_rlist_add(ip, &rlist, bstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) bstart = bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) blen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) blks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (bstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) gfs2_rlist_add(ip, &rlist, bstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) gfs2_rlist_alloc(&rlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) for (x = 0; x < rlist.rl_rgrps; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) rgd = gfs2_glock2rgrp(rlist.rl_ghs[x].gh_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) rg_blocks += rgd->rd_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) goto out_rlist_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + RES_INDIRECT +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) RES_STATFS + RES_QUOTA, blks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) gfs2_trans_add_meta(ip->i_gl, indbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) eablk = (__be64 *)(indbh->b_data + sizeof(struct gfs2_meta_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) bstart = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) rgd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) blen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) for (; eablk < end; eablk++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) u64 bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if (!*eablk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) bn = be64_to_cpu(*eablk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (bstart + blen == bn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) blen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) if (bstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) gfs2_free_meta(ip, rgd, bstart, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) bstart = bn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) rgd = gfs2_blk2rgrpd(sdp, bstart, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) blen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) *eablk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) gfs2_add_inode_blocks(&ip->i_inode, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) if (bstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) gfs2_free_meta(ip, rgd, bstart, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) ip->i_diskflags &= ~GFS2_DIF_EA_INDIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) error = gfs2_meta_inode_buffer(ip, &dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) gfs2_trans_add_meta(ip->i_gl, dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) gfs2_dinode_out(ip, dibh->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) brelse(dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) out_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) out_rlist_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) gfs2_rlist_free(&rlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) brelse(indbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) static int ea_dealloc_block(struct gfs2_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) struct gfs2_rgrpd *rgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) struct buffer_head *dibh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) if (!rgd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) gfs2_consist_inode(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_DINODE + RES_STATFS +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) RES_QUOTA, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) gfs2_free_meta(ip, rgd, ip->i_eattr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) ip->i_eattr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) gfs2_add_inode_blocks(&ip->i_inode, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) error = gfs2_meta_inode_buffer(ip, &dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) gfs2_trans_add_meta(ip->i_gl, dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) gfs2_dinode_out(ip, dibh->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) brelse(dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) out_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) * gfs2_ea_dealloc - deallocate the extended attribute fork
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) * @ip: the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) int gfs2_ea_dealloc(struct gfs2_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) error = gfs2_rindex_update(GFS2_SB(&ip->i_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) error = ea_foreach(ip, ea_dealloc_unstuffed, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) goto out_quota;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (ip->i_diskflags & GFS2_DIF_EA_INDIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) error = ea_dealloc_indirect(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) goto out_quota;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) error = ea_dealloc_block(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) out_quota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) gfs2_quota_unhold(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) return error;
^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) static const struct xattr_handler gfs2_xattr_user_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) .prefix = XATTR_USER_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) .flags = GFS2_EATYPE_USR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) .get = gfs2_xattr_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) .set = gfs2_xattr_set,
^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) static const struct xattr_handler gfs2_xattr_security_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) .prefix = XATTR_SECURITY_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) .flags = GFS2_EATYPE_SECURITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) .get = gfs2_xattr_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) .set = gfs2_xattr_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) const struct xattr_handler *gfs2_xattr_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) &gfs2_xattr_user_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) &gfs2_xattr_security_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) &posix_acl_access_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) &posix_acl_default_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)