提交 cf1d6c76 编写于 作者: T Tiger Yang 提交者: Mark Fasheh

ocfs2: Add extended attribute support

This patch implements storing extended attributes both in inode or a single
external block. We only store EA's in-inode when blocksize > 512 or that
inode block has free space for it. When an EA's value is larger than 80
bytes, we will store the value via b-tree outside inode or block.
Signed-off-by: NTiger Yang <tiger.yang@oracle.com>
Signed-off-by: NMark Fasheh <mfasheh@suse.com>
上级 fdd77704
...@@ -36,6 +36,8 @@ ocfs2-objs := \ ...@@ -36,6 +36,8 @@ ocfs2-objs := \
uptodate.o \ uptodate.o \
ver.o \ ver.o \
xattr.o \ xattr.o \
xattr_user.o \
xattr_trusted.o
ocfs2_stackglue-objs := stackglue.o ocfs2_stackglue-objs := stackglue.o
ocfs2_stack_o2cb-objs := stack_o2cb.o ocfs2_stack_o2cb-objs := stack_o2cb.o
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "mmap.h" #include "mmap.h"
#include "suballoc.h" #include "suballoc.h"
#include "super.h" #include "super.h"
#include "xattr.h"
#include "buffer_head_io.h" #include "buffer_head_io.h"
...@@ -2070,6 +2071,10 @@ const struct inode_operations ocfs2_file_iops = { ...@@ -2070,6 +2071,10 @@ const struct inode_operations ocfs2_file_iops = {
.setattr = ocfs2_setattr, .setattr = ocfs2_setattr,
.getattr = ocfs2_getattr, .getattr = ocfs2_getattr,
.permission = ocfs2_permission, .permission = ocfs2_permission,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ocfs2_listxattr,
.removexattr = generic_removexattr,
.fallocate = ocfs2_fallocate, .fallocate = ocfs2_fallocate,
.fiemap = ocfs2_fiemap, .fiemap = ocfs2_fiemap,
}; };
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "symlink.h" #include "symlink.h"
#include "sysfile.h" #include "sysfile.h"
#include "uptodate.h" #include "uptodate.h"
#include "xattr.h"
#include "buffer_head_io.h" #include "buffer_head_io.h"
...@@ -741,6 +742,13 @@ static int ocfs2_wipe_inode(struct inode *inode, ...@@ -741,6 +742,13 @@ static int ocfs2_wipe_inode(struct inode *inode,
goto bail_unlock_dir; goto bail_unlock_dir;
} }
/*Free extended attribute resources associated with this inode.*/
status = ocfs2_xattr_remove(inode, di_bh);
if (status < 0) {
mlog_errno(status);
goto bail_unlock_dir;
}
status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode, status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode,
orphan_dir_bh); orphan_dir_bh);
if (status < 0) if (status < 0)
......
...@@ -40,6 +40,9 @@ struct ocfs2_inode_info ...@@ -40,6 +40,9 @@ struct ocfs2_inode_info
/* protects allocation changes on this inode. */ /* protects allocation changes on this inode. */
struct rw_semaphore ip_alloc_sem; struct rw_semaphore ip_alloc_sem;
/* protects extended attribute changes on this inode */
struct rw_semaphore ip_xattr_sem;
/* These fields are protected by ip_lock */ /* These fields are protected by ip_lock */
spinlock_t ip_lock; spinlock_t ip_lock;
u32 ip_open_count; u32 ip_open_count;
......
...@@ -283,6 +283,9 @@ int ocfs2_journal_dirty_data(handle_t *handle, ...@@ -283,6 +283,9 @@ int ocfs2_journal_dirty_data(handle_t *handle,
/* simple file updates like chmod, etc. */ /* simple file updates like chmod, etc. */
#define OCFS2_INODE_UPDATE_CREDITS 1 #define OCFS2_INODE_UPDATE_CREDITS 1
/* extended attribute block update */
#define OCFS2_XATTR_BLOCK_UPDATE_CREDITS 1
/* group extend. inode update and last group update. */ /* group extend. inode update and last group update. */
#define OCFS2_GROUP_EXTEND_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1) #define OCFS2_GROUP_EXTEND_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
...@@ -340,6 +343,13 @@ int ocfs2_journal_dirty_data(handle_t *handle, ...@@ -340,6 +343,13 @@ int ocfs2_journal_dirty_data(handle_t *handle,
#define OCFS2_RENAME_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 3 \ #define OCFS2_RENAME_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 3 \
+ OCFS2_UNLINK_CREDITS) + OCFS2_UNLINK_CREDITS)
/* global bitmap dinode, group desc., relinked group,
* suballocator dinode, group desc., relinked group,
* dinode, xattr block */
#define OCFS2_XATTR_BLOCK_CREATE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + \
+ OCFS2_INODE_UPDATE_CREDITS \
+ OCFS2_XATTR_BLOCK_UPDATE_CREDITS)
/* /*
* Please note that the caller must make sure that root_el is the root * Please note that the caller must make sure that root_el is the root
* of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include "symlink.h" #include "symlink.h"
#include "sysfile.h" #include "sysfile.h"
#include "uptodate.h" #include "uptodate.h"
#include "xattr.h"
#include "buffer_head_io.h" #include "buffer_head_io.h"
...@@ -1918,4 +1919,8 @@ const struct inode_operations ocfs2_dir_iops = { ...@@ -1918,4 +1919,8 @@ const struct inode_operations ocfs2_dir_iops = {
.setattr = ocfs2_setattr, .setattr = ocfs2_setattr,
.getattr = ocfs2_getattr, .getattr = ocfs2_getattr,
.permission = ocfs2_permission, .permission = ocfs2_permission,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ocfs2_listxattr,
.removexattr = generic_removexattr,
}; };
...@@ -188,6 +188,7 @@ enum ocfs2_mount_options ...@@ -188,6 +188,7 @@ enum ocfs2_mount_options
OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */ OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */ OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */ OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
OCFS2_MOUNT_NOUSERXATTR = 1 << 6, /* No user xattr */
}; };
#define OCFS2_OSB_SOFT_RO 0x0001 #define OCFS2_OSB_SOFT_RO 0x0001
...@@ -218,6 +219,7 @@ struct ocfs2_super ...@@ -218,6 +219,7 @@ struct ocfs2_super
u32 bitmap_cpg; u32 bitmap_cpg;
u8 *uuid; u8 *uuid;
char *uuid_str; char *uuid_str;
u32 uuid_hash;
u8 *vol_label; u8 *vol_label;
u64 first_cluster_group_blkno; u64 first_cluster_group_blkno;
u32 fs_generation; u32 fs_generation;
......
...@@ -570,7 +570,7 @@ struct ocfs2_super_block { ...@@ -570,7 +570,7 @@ struct ocfs2_super_block {
/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
before tunefs required */ before tunefs required */
__le16 s_tunefs_flag; __le16 s_tunefs_flag;
__le32 s_reserved1; __le32 s_uuid_hash; /* hash value of uuid */
__le64 s_first_cluster_group; /* Block offset of 1st cluster __le64 s_first_cluster_group; /* Block offset of 1st cluster
* group header */ * group header */
/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
...@@ -787,7 +787,11 @@ struct ocfs2_xattr_tree_root { ...@@ -787,7 +787,11 @@ struct ocfs2_xattr_tree_root {
/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */ /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
}; };
#define OCFS2_XATTR_INDEXED 0x1 #define OCFS2_XATTR_INDEXED 0x1
#define OCFS2_HASH_SHIFT 5
#define OCFS2_XATTR_ROUND 3
#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
~(OCFS2_XATTR_ROUND))
/* /*
* On disk structure for xattr block. * On disk structure for xattr block.
......
...@@ -493,9 +493,9 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb, ...@@ -493,9 +493,9 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
return status; return status;
} }
int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb,
struct ocfs2_extent_list *root_el, int blocks,
struct ocfs2_alloc_context **ac) struct ocfs2_alloc_context **ac)
{ {
int status; int status;
u32 slot; u32 slot;
...@@ -507,7 +507,7 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, ...@@ -507,7 +507,7 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
goto bail; goto bail;
} }
(*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(root_el); (*ac)->ac_bits_wanted = blocks;
(*ac)->ac_which = OCFS2_AC_USE_META; (*ac)->ac_which = OCFS2_AC_USE_META;
slot = osb->slot_num; slot = osb->slot_num;
(*ac)->ac_group_search = ocfs2_block_group_search; (*ac)->ac_group_search = ocfs2_block_group_search;
...@@ -532,6 +532,15 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, ...@@ -532,6 +532,15 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
return status; return status;
} }
int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
struct ocfs2_extent_list *root_el,
struct ocfs2_alloc_context **ac)
{
return ocfs2_reserve_new_metadata_blocks(osb,
ocfs2_extend_meta_needed(root_el),
ac);
}
static int ocfs2_steal_inode_from_other_nodes(struct ocfs2_super *osb, static int ocfs2_steal_inode_from_other_nodes(struct ocfs2_super *osb,
struct ocfs2_alloc_context *ac) struct ocfs2_alloc_context *ac)
{ {
......
...@@ -67,6 +67,9 @@ static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac) ...@@ -67,6 +67,9 @@ static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac)
int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
struct ocfs2_extent_list *root_el, struct ocfs2_extent_list *root_el,
struct ocfs2_alloc_context **ac); struct ocfs2_alloc_context **ac);
int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb,
int blocks,
struct ocfs2_alloc_context **ac);
int ocfs2_reserve_new_inode(struct ocfs2_super *osb, int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
struct ocfs2_alloc_context **ac); struct ocfs2_alloc_context **ac);
int ocfs2_reserve_clusters(struct ocfs2_super *osb, int ocfs2_reserve_clusters(struct ocfs2_super *osb,
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include "sysfile.h" #include "sysfile.h"
#include "uptodate.h" #include "uptodate.h"
#include "ver.h" #include "ver.h"
#include "xattr.h"
#include "buffer_head_io.h" #include "buffer_head_io.h"
...@@ -154,6 +155,8 @@ enum { ...@@ -154,6 +155,8 @@ enum {
Opt_localalloc, Opt_localalloc,
Opt_localflocks, Opt_localflocks,
Opt_stack, Opt_stack,
Opt_user_xattr,
Opt_nouser_xattr,
Opt_err, Opt_err,
}; };
...@@ -173,6 +176,8 @@ static const match_table_t tokens = { ...@@ -173,6 +176,8 @@ static const match_table_t tokens = {
{Opt_localalloc, "localalloc=%d"}, {Opt_localalloc, "localalloc=%d"},
{Opt_localflocks, "localflocks"}, {Opt_localflocks, "localflocks"},
{Opt_stack, "cluster_stack=%s"}, {Opt_stack, "cluster_stack=%s"},
{Opt_user_xattr, "user_xattr"},
{Opt_nouser_xattr, "nouser_xattr"},
{Opt_err, NULL} {Opt_err, NULL}
}; };
...@@ -848,6 +853,12 @@ static int ocfs2_parse_options(struct super_block *sb, ...@@ -848,6 +853,12 @@ static int ocfs2_parse_options(struct super_block *sb,
case Opt_data_writeback: case Opt_data_writeback:
mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK; mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
break; break;
case Opt_user_xattr:
mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
break;
case Opt_nouser_xattr:
mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
break;
case Opt_atime_quantum: case Opt_atime_quantum:
if (match_int(&args[0], &option)) { if (match_int(&args[0], &option)) {
status = 0; status = 0;
...@@ -1135,6 +1146,7 @@ static void ocfs2_inode_init_once(void *data) ...@@ -1135,6 +1146,7 @@ static void ocfs2_inode_init_once(void *data)
oi->ip_dir_start_lookup = 0; oi->ip_dir_start_lookup = 0;
init_rwsem(&oi->ip_alloc_sem); init_rwsem(&oi->ip_alloc_sem);
init_rwsem(&oi->ip_xattr_sem);
mutex_init(&oi->ip_io_mutex); mutex_init(&oi->ip_io_mutex);
oi->ip_blkno = 0ULL; oi->ip_blkno = 0ULL;
...@@ -1378,6 +1390,7 @@ static int ocfs2_initialize_super(struct super_block *sb, ...@@ -1378,6 +1390,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
sb->s_fs_info = osb; sb->s_fs_info = osb;
sb->s_op = &ocfs2_sops; sb->s_op = &ocfs2_sops;
sb->s_export_op = &ocfs2_export_ops; sb->s_export_op = &ocfs2_export_ops;
sb->s_xattr = ocfs2_xattr_handlers;
sb->s_time_gran = 1; sb->s_time_gran = 1;
sb->s_flags |= MS_NOATIME; sb->s_flags |= MS_NOATIME;
/* this is needed to support O_LARGEFILE */ /* this is needed to support O_LARGEFILE */
...@@ -1574,6 +1587,7 @@ static int ocfs2_initialize_super(struct super_block *sb, ...@@ -1574,6 +1587,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
osb->first_cluster_group_blkno = osb->first_cluster_group_blkno =
le64_to_cpu(di->id2.i_super.s_first_cluster_group); le64_to_cpu(di->id2.i_super.s_first_cluster_group);
osb->fs_generation = le32_to_cpu(di->i_fs_generation); osb->fs_generation = le32_to_cpu(di->i_fs_generation);
osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
mlog(0, "vol_label: %s\n", osb->vol_label); mlog(0, "vol_label: %s\n", osb->vol_label);
mlog(0, "uuid: %s\n", osb->uuid_str); mlog(0, "uuid: %s\n", osb->uuid_str);
mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n", mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "inode.h" #include "inode.h"
#include "journal.h" #include "journal.h"
#include "symlink.h" #include "symlink.h"
#include "xattr.h"
#include "buffer_head_io.h" #include "buffer_head_io.h"
...@@ -168,10 +169,18 @@ const struct inode_operations ocfs2_symlink_inode_operations = { ...@@ -168,10 +169,18 @@ const struct inode_operations ocfs2_symlink_inode_operations = {
.follow_link = ocfs2_follow_link, .follow_link = ocfs2_follow_link,
.getattr = ocfs2_getattr, .getattr = ocfs2_getattr,
.setattr = ocfs2_setattr, .setattr = ocfs2_setattr,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ocfs2_listxattr,
.removexattr = generic_removexattr,
}; };
const struct inode_operations ocfs2_fast_symlink_inode_operations = { const struct inode_operations ocfs2_fast_symlink_inode_operations = {
.readlink = ocfs2_readlink, .readlink = ocfs2_readlink,
.follow_link = ocfs2_follow_link, .follow_link = ocfs2_follow_link,
.getattr = ocfs2_getattr, .getattr = ocfs2_getattr,
.setattr = ocfs2_setattr, .setattr = ocfs2_setattr,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ocfs2_listxattr,
.removexattr = generic_removexattr,
}; };
此差异已折叠。
/* -*- mode: c; c-basic-offset: 8; -*-
* vim: noexpandtab sw=8 ts=8 sts=0:
*
* xattr.h
*
* Function prototypes
*
* Copyright (C) 2008 Oracle. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 021110-1307, USA.
*/
#ifndef OCFS2_XATTR_H
#define OCFS2_XATTR_H
#include <linux/init.h>
#include <linux/xattr.h>
enum ocfs2_xattr_type {
OCFS2_XATTR_INDEX_USER = 1,
OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS,
OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT,
OCFS2_XATTR_INDEX_TRUSTED,
OCFS2_XATTR_INDEX_SECURITY,
OCFS2_XATTR_MAX
};
extern struct xattr_handler ocfs2_xattr_user_handler;
extern struct xattr_handler ocfs2_xattr_trusted_handler;
extern ssize_t ocfs2_listxattr(struct dentry *, char *, size_t);
extern int ocfs2_xattr_get(struct inode *, int, const char *, void *, size_t);
extern int ocfs2_xattr_set(struct inode *, int, const char *, const void *,
size_t, int);
extern int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh);
extern struct xattr_handler *ocfs2_xattr_handlers[];
#endif /* OCFS2_XATTR_H */
/* -*- mode: c; c-basic-offset: 8; -*-
* vim: noexpandtab sw=8 ts=8 sts=0:
*
* xattr_trusted.c
*
* Copyright (C) 2008 Oracle. All rights reserved.
*
* CREDITS:
* Lots of code in this file is taken from ext3.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 021110-1307, USA.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/string.h>
#define MLOG_MASK_PREFIX ML_INODE
#include <cluster/masklog.h>
#include "ocfs2.h"
#include "alloc.h"
#include "dlmglue.h"
#include "file.h"
#include "ocfs2_fs.h"
#include "xattr.h"
#define XATTR_TRUSTED_PREFIX "trusted."
static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list,
size_t list_size, const char *name,
size_t name_len)
{
const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX) - 1;
const size_t total_len = prefix_len + name_len + 1;
if (list && total_len <= list_size) {
memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
memcpy(list + prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
}
return total_len;
}
static int ocfs2_xattr_trusted_get(struct inode *inode, const char *name,
void *buffer, size_t size)
{
if (strcmp(name, "") == 0)
return -EINVAL;
return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED, name,
buffer, size);
}
static int ocfs2_xattr_trusted_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags)
{
if (strcmp(name, "") == 0)
return -EINVAL;
return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED, name, value,
size, flags);
}
struct xattr_handler ocfs2_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX,
.list = ocfs2_xattr_trusted_list,
.get = ocfs2_xattr_trusted_get,
.set = ocfs2_xattr_trusted_set,
};
/* -*- mode: c; c-basic-offset: 8; -*-
* vim: noexpandtab sw=8 ts=8 sts=0:
*
* xattr_user.c
*
* Copyright (C) 2008 Oracle. All rights reserved.
*
* CREDITS:
* Lots of code in this file is taken from ext3.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 021110-1307, USA.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/string.h>
#define MLOG_MASK_PREFIX ML_INODE
#include <cluster/masklog.h>
#include "ocfs2.h"
#include "alloc.h"
#include "dlmglue.h"
#include "file.h"
#include "ocfs2_fs.h"
#include "xattr.h"
#define XATTR_USER_PREFIX "user."
static size_t ocfs2_xattr_user_list(struct inode *inode, char *list,
size_t list_size, const char *name,
size_t name_len)
{
const size_t prefix_len = sizeof(XATTR_USER_PREFIX) - 1;
const size_t total_len = prefix_len + name_len + 1;
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
return 0;
if (list && total_len <= list_size) {
memcpy(list, XATTR_USER_PREFIX, prefix_len);
memcpy(list + prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
}
return total_len;
}
static int ocfs2_xattr_user_get(struct inode *inode, const char *name,
void *buffer, size_t size)
{
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
if (strcmp(name, "") == 0)
return -EINVAL;
if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
return -EOPNOTSUPP;
return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name,
buffer, size);
}
static int ocfs2_xattr_user_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags)
{
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
if (strcmp(name, "") == 0)
return -EINVAL;
if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
return -EOPNOTSUPP;
return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER, name, value,
size, flags);
}
struct xattr_handler ocfs2_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX,
.list = ocfs2_xattr_user_list,
.get = ocfs2_xattr_user_get,
.set = ocfs2_xattr_user_set,
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册