[Ocfs2-tools-devel] [PATCH 6/6] libocfs2: add set and get xattr operations

Tao Ma tao.ma at oracle.com
Wed Jul 29 22:06:15 PDT 2009



Tiger Yang wrote:
> This patch implement set and get xattr in libocfs2,
> they are very similiar with the functions in kernel.
> 
> Signed-off-by: Tiger Yang <tiger.yang at oracle.com>
> ---
>  include/ocfs2/ocfs2.h |   12 +
>  libocfs2/xattr.c      | 2714 ++++++++++++++++++++++++++++++++++++++++++++++++-
>  libocfs2/xattr.h      |   15 +
>  3 files changed, 2734 insertions(+), 7 deletions(-)
> 
> diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
> index 381ec43..0ecd70a 100644
> --- a/include/ocfs2/ocfs2.h
> +++ b/include/ocfs2/ocfs2.h
> @@ -1176,5 +1176,17 @@ errcode_t ocfs2_xattr_get_clusters(ocfs2_cached_inode *cinode,
>  errcode_t ocfs2_xattr_value_shrink(ocfs2_filesys *fs,
>  				   struct ocfs2_xattr_value_root *xv,
>  				   uint32_t new_clusters);
> +const char *ocfs2_xattr_get_prefix(int name_index);
> +errcode_t ocfs2_xattr_get_generic(ocfs2_cached_inode *ci, const char *name,
> +				  char *buf, size_t count, size_t *got);
> +errcode_t ocfs2_xattr_set_generic(ocfs2_cached_inode *ci,
> +				  const char *name,
> +				  const char *buf,
> +				  size_t count);
> +errcode_t ocfs2_xattr_name_iterate(ocfs2_cached_inode *ci,
> +				  int (*func)(ocfs2_cached_inode *ci,
> +						const char *name,
> +						void *priv_data),
> +				  void *priv_data);
>  
>  #endif  /* _FILESYS_H */
> diff --git a/libocfs2/xattr.c b/libocfs2/xattr.c
> index c6f69c4..12d23df 100644
> --- a/libocfs2/xattr.c
> +++ b/libocfs2/xattr.c
> @@ -14,18 +14,88 @@
>   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>   * General Public License for more details.
>   */
> +#include <stdlib.h>
>  #include <string.h>
>  #include <inttypes.h>
> +#include <assert.h>
>  
>  #include "ocfs2/byteorder.h"
>  #include "ocfs2/ocfs2.h"
> +#include "xattr.h"
> +#include "extent_tree.h"
> +
> +#define DEBUG_XATTR 1
> +#ifdef DEBUG_XATTR
> +#define DEBUG(...) printf(__VA_ARGS__)
> +#define ASSERT assert
> +#else
> +#define DEBUG(...)
> +#define ASSERT
> +#endif
> +
> +#define OCFS2_XATTR_ROOT_SIZE	(sizeof(struct ocfs2_xattr_def_value_root))
> +#define OCFS2_XATTR_ABORT	0x01
> +#define OCFS2_XATTR_ERROR	0x02
> +#define OCFS2_XATTR_HEADER_GAP	4
> +
> +#define XATTR_NODATA	(-61)
> +#define XATTR_NOSPC	(-28)
> +
> +#define HEADER_SIZE     (sizeof(struct ocfs2_xattr_header))
> +#define ENTRY_SIZE      (sizeof(struct ocfs2_xattr_entry))
> +#define bucket_xh(_b)	((struct ocfs2_xattr_header *)(_b)->xb_buf)
>  
>  struct ocfs2_xattr_def_value_root {
>  	struct ocfs2_xattr_value_root   xv;
>  	struct ocfs2_extent_rec         er;
>  };
>  
> -#define OCFS2_XATTR_ROOT_SIZE	(sizeof(struct ocfs2_xattr_def_value_root))
you added it above whild deleting it here? So maybe don't change its line?
> +static struct ocfs2_xattr_def_value_root def_xv = {
> +	.xv.xr_list.l_count = 1,
> +};
> +
<snip>
> @@ -212,7 +290,7 @@ errcode_t ocfs2_read_xattr_block(ocfs2_filesys *fs,
>  	if (ret)
>  		return ret;
>  
> -	ret = ocfs2_read_blocks(fs->fs_io, blkno, 1, blk);
> +	ret = ocfs2_read_blocks(fs, blkno, 1, blk);
I have fixed it and you can rebase your branch for it.
>  	if (ret)
>  		goto out;
>
<snip>
I will trust you for coping xattr functions from kernel to userspace. 
And I just skimmed it, it looks well but I am afraid you have to change 
some comments since there are so many "bh" things.
> +/*
> + * Iterate the xattr names on inode 'ci'.  If 'func' returns
> + * OCFS2_XATTR_ABORT or OCFS2_XATTR_ERROR, stop iteration.
> + * If OCFS2_XATTR_ERROR, return an error from ocfs2_xattr_name_iterate.
> + *
> + * If you modify an xattr, you must restart your iteration - there is
> + * no guarantee it is in a consistent state.
> + */
> +
> +errcode_t ocfs2_xattr_name_iterate(ocfs2_cached_inode *ci,
> +				   int (*func)(ocfs2_cached_inode *ci,
> +						const char *name,
> +						void *priv_data),
> +				   void *priv_data)
> +{
> +	errcode_t ret = 0;
> +	return ret;
> +}
What's this?

Regards,
Tao



More information about the Ocfs2-tools-devel mailing list