Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 680222 Details for
Bug 850426
gfs2: Add xgetdents syscall to the kernel
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Updated patch
xgetdents-try7-01172013-complete-but-inefficient.patch (text/plain), 41.31 KB, created by
Abhijith Das
on 2013-01-17 14:06:48 UTC
(
hide
)
Description:
Updated patch
Filename:
MIME Type:
Creator:
Abhijith Das
Created:
2013-01-17 14:06:48 UTC
Size:
41.31 KB
patch
obsolete
>diff --git a/arch/x86/syscalls/syscall_32.tbl b/arch/x86/syscalls/syscall_32.tbl >index a85f407..35aeb58 100644 >--- a/arch/x86/syscalls/syscall_32.tbl >+++ b/arch/x86/syscalls/syscall_32.tbl >@@ -358,4 +358,5 @@ > 349 i386 kcmp sys_kcmp > 350 i386 finit_module sys_finit_module > 351 i386 xstat sys_xstat >-352 i386 fxstat sys_fxstat >\ No newline at end of file >+352 i386 fxstat sys_fxstat >+353 i386 xgetdents sys_xgetdents >diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl >index d9bac28..8b68501 100644 >--- a/arch/x86/syscalls/syscall_64.tbl >+++ b/arch/x86/syscalls/syscall_64.tbl >@@ -322,6 +322,7 @@ > 313 common finit_module sys_finit_module > 314 common xstat sys_xstat > 315 common fxstat sys_fxstat >+316 common xgetdents sys_xgetdents > > # > # x32-specific system call numbers start at 512 to avoid cache impact >diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c >index 7179478..4a4bc46 100644 >--- a/fs/gfs2/dir.c >+++ b/fs/gfs2/dir.c >@@ -78,9 +78,6 @@ > > #define MAX_RA_BLOCKS 32 /* max read-ahead blocks */ > >-#define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) >-#define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) >- > struct qstr gfs2_qdot __read_mostly; > struct qstr gfs2_qdotdot __read_mostly; > >@@ -1159,17 +1156,13 @@ out_kfree: > * lt: returns -1 > * eq: returns 0 > */ >- >-static int compare_dents(const void *a, const void *b) >+int compare_dents_i(const struct gfs2_dirent *dent_a, >+ const struct gfs2_dirent *dent_b) > { >- const struct gfs2_dirent *dent_a, *dent_b; > u32 hash_a, hash_b; > int ret = 0; > >- dent_a = *(const struct gfs2_dirent **)a; > hash_a = be32_to_cpu(dent_a->de_hash); >- >- dent_b = *(const struct gfs2_dirent **)b; > hash_b = be32_to_cpu(dent_b->de_hash); > > if (hash_a > hash_b) >@@ -1191,28 +1184,43 @@ static int compare_dents(const void *a, const void *b) > return ret; > } > >+static int compare_dents(const void *a, const void *b) >+{ >+ return compare_dents_i(*(const struct gfs2_dirent **)a, >+ *(const struct gfs2_dirent **)b); >+} >+ >+int process_dent(const struct gfs2_dirent *dent, loff_t off, void *opaque, >+ filldir_t filler) >+{ >+ return filler(opaque, (const char *)(dent + 1), >+ be16_to_cpu(dent->de_name_len), >+ off, be64_to_cpu(dent->de_inum.no_addr), >+ be16_to_cpu(dent->de_type)); >+} >+ > /** >- * do_filldir_main - read out directory entries >- * @dip: The GFS2 inode >- * @offset: The offset in the file to read from >- * @opaque: opaque data to pass to filldir >- * @filldir: The function to pass entries to >- * @darr: an array of struct gfs2_dirent pointers to read >+ * foreach_dent - run through list of dents and call pd_fn, keeping in >+ * mind hash collisions >+ * @offset : The offset in the file to read from >+ * @opaque : opaque data to pass to pd_fn >+ * @filldir: The filler function to psas to pd_fn >+ * @darr : an array of struct gfs2_dirent pointers to read > * @entries: the number of entries in darr >- * @copied: pointer to int that's non-zero if a entry has been copied out >+ * @copied : pointer to int that's non-zero if a entry has been copied out >+ * @pd_fn : The function to process a dentry > * > * Jump through some hoops to make sure that if there are hash collsions, > * they are read out at the beginning of a buffer. We want to minimize > * the possibility that they will fall into different readdir buffers or > * that someone will want to seek to that location. > * >- * Returns: errno, >0 on exception from filldir >+ * Returns: errno, >0 on exception from pd_fn > */ > >-static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, >- void *opaque, filldir_t filldir, >- const struct gfs2_dirent **darr, u32 entries, >- int *copied) >+int foreach_dent(u64 *offset, void *opaque, filldir_t filldir, >+ const struct gfs2_dirent **darr, u32 entries, >+ int *copied, process_dent_t pd_fn) > { > const struct gfs2_dirent *dent, *dent_next; > u64 off, off_next; >@@ -1220,8 +1228,6 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, > int run = 0; > int error = 0; > >- sort(darr, entries, sizeof(struct gfs2_dirent *), compare_dents, NULL); >- > dent_next = darr[0]; > off_next = be32_to_cpu(dent_next->de_hash); > off_next = gfs2_disk_hash2offset(off_next); >@@ -1250,26 +1256,51 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, > continue; > *offset = off; > } >- >- error = filldir(opaque, (const char *)(dent + 1), >- be16_to_cpu(dent->de_name_len), >- off, be64_to_cpu(dent->de_inum.no_addr), >- be16_to_cpu(dent->de_type)); >+ error = pd_fn(dent, off, opaque, filldir); > if (error) > return 1; > > *copied = 1; > } >- > /* Increment the *offset by one, so the next time we come into the > do_filldir fxn, we get the next entry instead of the last one in the > current leaf */ > > (*offset)++; >- > return 0; > } > >+/** >+ * do_filldir_main - read out directory entries >+ * @dip: The GFS2 inode >+ * @offset: The offset in the file to read from >+ * @opaque: opaque data to pass to filldir >+ * @filldir: The function to pass entries to, if NULL call xreaddir_collect_dents >+ * @darr: an array of struct gfs2_dirent pointers to read >+ * @entries: the number of entries in darr >+ * @copied: pointer to int that's non-zero if a entry has been copied out >+ * >+ * Returns: 0 on success and non-zero on exception >+ */ >+ >+static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, >+ void *opaque, filldir_t filldir, >+ const struct gfs2_dirent **darr, u32 entries, >+ int *copied) >+{ >+ sort(darr, entries, sizeof(struct gfs2_dirent *), compare_dents, NULL); >+ >+ /* >+ * If filldir is NULL, we got here through xreaddir and need to >+ * call the appropriate handler >+ */ >+ if (!filldir) >+ return xreaddir_collect_dents(opaque, offset, darr, entries); >+ >+ return foreach_dent(offset, opaque, filldir, darr, entries, >+ copied, process_dent); >+} >+ > static void *gfs2_alloc_sort_buffer(unsigned size) > { > void *ptr = NULL; >diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h >index 98c960b..9375818 100644 >--- a/fs/gfs2/dir.h >+++ b/fs/gfs2/dir.h >@@ -13,10 +13,45 @@ > #include <linux/dcache.h> > #include <linux/crc32.h> > >+#define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) >+#define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) >+ > struct inode; > struct gfs2_inode; > struct gfs2_inum; > >+struct xdirent { >+ unsigned int x_xattr_count; >+ unsigned int x_xattr_cap; >+ struct xattr **x_xattrs; >+ struct gfs2_inode *x_inode; >+ struct gfs2_dirent x_dent; >+}; >+ >+struct xreaddir_ctx { >+ int xc_err; >+ unsigned int xc_entries; >+ unsigned int xc_bufsize; >+ unsigned int xc_flags; >+ unsigned int xc_mask; >+ size_t xc_ubufsize; >+ unsigned int xc_ubuf_ent_cap; >+ struct gfs2_inode *xc_dip; >+ char *xc_buf; >+ char *xc_buftop; >+ struct xdirent **xc_xdents; >+ void *xc_opaque; >+}; >+ >+typedef int (*process_dent_t)(const struct gfs2_dirent *, loff_t, void *, filldir_t); >+ >+extern int compare_dents_i(const struct gfs2_dirent *dent_a, >+ const struct gfs2_dirent *dent_b); >+extern int xreaddir_collect_dents(void *opaque, u64 *offset, >+ const struct gfs2_dirent **darr, u32 entries); >+extern int foreach_dent(u64 *offset, void *opaque, filldir_t filldir, >+ const struct gfs2_dirent **darr, u32 entries, >+ int *copied, process_dent_t pd_fn); > extern struct inode *gfs2_dir_search(struct inode *dir, > const struct qstr *filename); > extern int gfs2_dir_check(struct inode *dir, const struct qstr *filename, >diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c >index 06b7092..16bbd4f 100644 >--- a/fs/gfs2/file.c >+++ b/fs/gfs2/file.c >@@ -16,6 +16,9 @@ > #include <linux/blkdev.h> > #include <linux/mm.h> > #include <linux/mount.h> >+#include <linux/stat.h> >+#include <linux/sort.h> >+#include <linux/xattr.h> > #include <linux/fs.h> > #include <linux/gfs2_ondisk.h> > #include <linux/falloc.h> >@@ -39,6 +42,7 @@ > #include "rgrp.h" > #include "trans.h" > #include "util.h" >+#include "xattr.h" > > /** > * gfs2_llseek - seek to a location in a file >@@ -114,6 +118,377 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) > } > > /** >+ * compare_dent_iblks - compare directory entries by inode blk# >+ * @a: first dent >+ * @b: second dent >+ * >+ * When comparing the blk# of @a to @b: >+ * gt: returns 1 >+ * lt: returns -1 >+ * eq: returns 0 >+ */ >+static int compare_xdent_iblks(const void *a, const void *b) >+{ >+ const struct xdirent *x_a, *x_b; >+ const struct gfs2_dirent *dent_a, *dent_b; >+ >+ x_a = *(const struct xdirent **)a; >+ x_b = *(const struct xdirent **)b; >+ >+ dent_a = &x_a->x_dent; >+ dent_b = &x_b->x_dent; >+ >+ if (be64_to_cpu(dent_a->de_inum.no_addr) > >+ be64_to_cpu(dent_b->de_inum.no_addr)) >+ return 1; >+ else >+ return -1; >+} >+ >+/** >+ * compare_xdents - compare directory entries by hash value >+ * @a: first dent >+ * @b: second dent >+ * >+ * Use compare_dents_i to compare >+ */ >+static int compare_xdents(const void *a, const void *b) >+{ >+ const struct xdirent *x_a, *x_b; >+ >+ x_a = *(const struct xdirent **)a; >+ x_b = *(const struct xdirent **)b; >+ >+ return compare_dents_i(&x_a->x_dent, &x_b->x_dent); >+} >+ >+/** >+ * xreaddir_free - Free all allocated buffers in context >+ * @ctx: The xreaddir context structure >+ */ >+static void xreaddir_free(struct xreaddir_ctx *ctx) >+{ >+ int i; >+ >+ if (!ctx || !ctx->xc_xdents || !ctx->xc_buf) >+ goto out; >+ >+ for (i=0; i<ctx->xc_entries; i++) { >+ if (!ctx->xc_xdents[i]) >+ continue; >+ if (!ctx->xc_xdents[i]->x_xattrs) >+ continue; >+ xattrs_free(ctx->xc_xdents[i]->x_xattrs, >+ ctx->xc_xdents[i]->x_xattr_count); >+ gfs2_free(ctx->xc_xdents[i]->x_xattrs); >+ } >+out: >+ if (ctx->xc_xdents) >+ gfs2_free(ctx->xc_xdents); >+ if (ctx->xc_buf) >+ gfs2_free(ctx->xc_buf); >+} >+ >+/** >+ * xreaddir_realloc - alloc/realloc the xreaddir context according to the >+ * number of entries >+ * @ctx: pointer to the context structure >+ * @entries: the number of entries >+ * >+ * Only a max of 99 dirents can come into this fn. It's the max >+ * a leaf block can hold and the caller (do_filldir_main) processes >+ * one leaf block at a time. >+ */ >+static int xreaddir_realloc(struct xreaddir_ctx *ctx, u32 entries) >+{ >+ unsigned int bufsize = ctx->xc_bufsize + 99 * sizeof(struct xdirent); >+ unsigned int ent_ptr_sz = (ctx->xc_entries + entries) * >+ sizeof(struct xdirent*); >+ unsigned int buftop = ctx->xc_buftop - ctx->xc_buf; >+ int error = -ENOMEM; >+ >+ ctx->xc_buf = gfs2_realloc(ctx->xc_buf, ctx->xc_bufsize, bufsize, >+ GFP_NOFS | __GFP_NOWARN); >+ if (!ctx->xc_buf) >+ goto out; >+ ctx->xc_bufsize = bufsize; >+ ctx->xc_buftop = ctx->xc_buf + buftop; >+ >+ ctx->xc_xdents = gfs2_realloc(ctx->xc_xdents, >+ (ctx->xc_entries * sizeof(struct xdirent*)), >+ ent_ptr_sz, GFP_NOFS | __GFP_NOWARN); >+ if (!ctx->xc_xdents) >+ goto out; >+ error = 0; >+out: >+ return error; >+} >+ >+/** >+ * estimate_xdirent_fit - Estimate the number of dirents that will fit >+ * for a buffer of a given size >+ * @bufsize: The size of the destination buffer >+ * >+ * This function gives the theoretical maximum number of xdirents that >+ * will fit in the given buffer space, assuming one character name i.e >+ * dent->de_name_len = 1, and 0 extended attributes. Note that the struct >+ * linux_xdirent accounts for one null-terminating character. >+ */ >+static __inline__ unsigned int estimate_xdirent_fit(size_t bufsize) >+{ >+ /* TODO: This needs to be a more accurate estimate, yet >+ * slightly more than what the buffer can hold so we always >+ * have enough entries to fill in. >+ */ >+ return bufsize / (sizeof(struct linux_xdirent) + 1); >+} >+ >+static __inline__ int gfs2_dirent_dot_or_dotdot(const struct gfs2_dirent *dent) >+{ >+ const char *name = (char *)(dent + 1); >+ >+ if (be16_to_cpu(dent->de_type) == DT_DIR) { >+ if (be16_to_cpu(dent->de_name_len) == 1 && name[0] == '.') >+ return 1; >+ if (be16_to_cpu(dent->de_name_len) == 2 && >+ strncmp(name, "..", 2) == 0) >+ return 1; >+ } >+ return 0; >+} >+ >+/* >+ * Add a gfs2_dirent to the xreaddir context >+ */ >+static int xreaddir_process_dents(const struct gfs2_dirent *dent, loff_t off, >+ void *opaque, filldir_t filldir) >+{ >+ struct xreaddir_ctx *ctx = (struct xreaddir_ctx *) opaque; >+ struct xdirent *xd = (struct xdirent *) ctx->xc_buftop; >+ >+ if (gfs2_dirent_dot_or_dotdot(dent)) >+ goto out; >+ >+ memset(xd, 0, sizeof(struct xdirent)); >+ memcpy(&xd->x_dent, (void *)dent, be16_to_cpu(dent->de_rec_len)); >+ ctx->xc_xdents[ctx->xc_entries++] = xd; >+ ctx->xc_buftop += sizeof(struct xdirent) + be16_to_cpu(dent->de_name_len); >+out: >+ return 0; >+} >+ >+/** >+ * xreaddir_collect_dents - Collects all gfs2_dirents passed to it into the >+ * context's buffer >+ * @opaque : pointer to the context >+ * @offset : the offset in the file to start reading from >+ * @darr : dents to copy >+ * @entries: number of dents in darr. >+ * >+ * Alloc/realloc the context buffer as necessary to accomodate the new set of >+ * dents. >+ */ >+int xreaddir_collect_dents(void *opaque, u64 *offset, const struct gfs2_dirent **darr, >+ u32 entries) >+{ >+ struct xreaddir_ctx *ctx = (struct xreaddir_ctx *) opaque; >+ int error = 0, i, copied = 0; >+ u64 off = *offset; >+ >+ if (ctx->xc_entries >= ctx->xc_ubuf_ent_cap) >+ return 1; >+ >+ error = xreaddir_realloc(ctx, entries); >+ if (error) >+ goto out; >+ /* Rearrange previous pointers as we have realloced ctx->xc_buf */ >+ for (i=ctx->xc_entries - 1; i>= 0; i--) >+ ctx->xc_xdents[i] = (struct xdirent *) >+ (ctx->xc_buf + ((void*)ctx->xc_xdents[i] >+ - (void*)ctx->xc_xdents[0])); >+ >+ error = foreach_dent(&off, opaque, NULL, darr, entries, &copied, >+ xreaddir_process_dents); >+out: >+ return error; >+} >+ >+/** >+ * xdirent_supply_info_i - Get xattrs for all dents and call the vfs xfiller >+ * fn with each dent and it's xstat info >+ * @ctx : The xreaddir context >+ * @filler: The vfs xfilldir function to fill the __user buffer with >+ * linux_xdirent structs >+ * @offset: Pointer to update with the offset of the last filled dent >+ * >+ * Get extended attributes for all dents, sort the list according to hash >+ * order and call filler() with the xstat info >+ */ >+static int xdirent_supply_info_i(struct xreaddir_ctx *ctx, xfilldir_t filler, >+ u64 *offset) >+{ >+ int error, i; >+ struct xdirent_info xinfo; >+ /* Get xattr info here */ >+ error = gfs2_get_inodes_xattr_lists(ctx->xc_xdents, ctx->xc_entries, >+ ctx->xc_mask); >+ >+ /* Sort back to dirent hash order */ >+ sort(ctx->xc_xdents, ctx->xc_entries, sizeof(struct xdirent *), >+ compare_xdents, NULL); >+ /* Run through the list, get stat info for each >+ * and supply to the filler function that will >+ * write to the user buffer >+ */ >+ for (i=0; i<ctx->xc_entries; i++) { >+ struct xdirent *xd = ctx->xc_xdents[i]; >+ struct gfs2_dirent *dent = &xd->x_dent; >+ >+ xinfo.xi_name = (const char *)(dent + 1); >+ xinfo.xi_namelen = be16_to_cpu(dent->de_name_len); >+ xinfo.xi_ino = be64_to_cpu(dent->de_inum.no_addr); >+ xinfo.xi_offset = be32_to_cpu(dent->de_hash); >+ xinfo.xi_offset = gfs2_disk_hash2offset(xinfo.xi_offset); >+ xinfo.xi_type = be16_to_cpu(dent->de_type); >+ xinfo.xi_xattr_count = xd->x_xattr_count; >+ >+ gfs2_getattr_i(xd->x_inode, &xinfo.xi_stat); >+ xinfo.xi_xattrs = xd->x_xattrs; >+ >+ error = filler(ctx->xc_opaque, &xinfo); >+ if (error) { >+ error = error == -EOVERFLOW ? 0 : error; >+ break; >+ } >+ /* advance offset so we don't read the same dent next time */ >+ *offset = xinfo.xi_offset + 1; >+ } >+ return error; >+} >+ >+/** >+ * xdirent_supply_info - Do all the prep work like lookups and locking >+ * for all the dents before we can call into >+ * the vfs filler function >+ * @ctx : The xreaddir context >+ * @filler: The vfs xfilldir function >+ * @offset: Will point to the offset of the last filled dirent >+ * >+ * Sort in block order, lookup and lock all the inodes in preparation >+ * of reading stat and xattr info and call xdirent_supply_info_i() >+ */ >+static int xdirent_supply_info(struct xreaddir_ctx *ctx, xfilldir_t filler, >+ u64 *offset) >+{ >+ struct gfs2_holder *ghs; >+ int error = -ENOMEM, i; >+ >+ /* First sort the dirent array in block order */ >+ sort(ctx->xc_xdents, ctx->xc_entries, sizeof(struct xdirent *), >+ compare_xdent_iblks, NULL); >+ >+ /* Lookup all the inodes for stat info */ >+ for (i=0; i<ctx->xc_entries; i++) { >+ struct xdirent *xd = ctx->xc_xdents[i]; >+ struct gfs2_dirent *dent = &xd->x_dent; >+ struct inode *inode; >+ >+ inode = gfs2_inode_lookup(ctx->xc_dip->i_inode.i_sb, >+ be16_to_cpu(dent->de_type), >+ be64_to_cpu(dent->de_inum.no_addr), >+ be64_to_cpu(dent->de_inum.no_formal_ino), >+ 0); >+ if (IS_ERR(inode)) { >+ xd->x_inode = NULL; >+ goto iput_iarr; >+ } >+ xd->x_inode = GFS2_I(inode); >+ } >+ >+ /* lock all inodes */ >+ ghs = kcalloc(ctx->xc_entries, sizeof(struct gfs2_holder), GFP_NOFS); >+ if (!ghs) >+ goto iput_iarr; >+ >+ for (i=0; i<ctx->xc_entries; i++) { >+ struct xdirent *xd = ctx->xc_xdents[i]; >+ gfs2_holder_init(xd->x_inode->i_gl, LM_ST_SHARED, LM_FLAG_ANY, >+ ghs + i); >+ } >+ >+ error = gfs2_glock_nq_m(ctx->xc_entries, ghs); >+ if (error) >+ goto free_ghs; >+ >+ error = xdirent_supply_info_i(ctx, filler, offset); >+ >+ gfs2_glock_dq_uninit_m(ctx->xc_entries, ghs); >+free_ghs: >+ kfree(ghs); >+iput_iarr: >+ for (i=0; i<ctx->xc_entries; i++) { >+ struct xdirent *xd = ctx->xc_xdents[i]; >+ if (xd->x_inode) >+ iput(&(xd->x_inode->i_inode)); >+ } >+ return error; >+} >+ >+/** >+ * gfs2_xreaddir - GFS2's implementation of xreaddir functionality >+ * @file : The directory to xreaddir >+ * @flags : flags used by xstat >+ * @mask : field mask for xstat and xattrs >+ * @count : size of user buffer; needed to estimate # of dents to process >+ * @opaque: vfs state to pass back with the filler fn >+ * @filler: The vfs filler function that will write to the user buffer >+ * >+ * Collect extended information (xstat, xattrs) about the dents in the >+ * given directory and pass them to filler(). When filler() signals that >+ * the user buffer is full, adjust file offset to next unread dent and >+ * return. >+ * >+ * Returns: 0 if successful and -ve errno if an exception occurred. >+ */ >+static int gfs2_xreaddir(struct file *file, unsigned int flags, unsigned int mask, >+ size_t count, void *opaque, xfilldir_t filler) >+{ >+ struct inode *dir = file->f_mapping->host; >+ struct gfs2_inode *dip = GFS2_I(dir); >+ struct gfs2_holder d_gh; >+ struct xreaddir_ctx ctx; >+ u64 offset = file->f_pos; >+ int error; >+ >+ memset(&ctx, 0, sizeof(struct xreaddir_ctx)); >+ ctx.xc_dip = dip; >+ ctx.xc_opaque = opaque; >+ ctx.xc_flags = flags; >+ ctx.xc_mask = mask; >+ ctx.xc_ubufsize = count; >+ ctx.xc_ubuf_ent_cap = estimate_xdirent_fit(count); >+ >+ gfs2_holder_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); >+ error = gfs2_glock_nq(&d_gh); >+ if (error) { >+ gfs2_holder_uninit(&d_gh); >+ goto out; >+ } >+ >+ error = gfs2_dir_read(dir, &offset, &ctx, NULL, &file->f_ra); >+ if (error >= 0) >+ error = xdirent_supply_info(&ctx, filler, &offset); >+ >+ file->f_pos = offset; >+ >+ gfs2_glock_dq_uninit(&d_gh); >+ >+ xreaddir_free(&ctx); >+out: >+ return error; >+} >+ >+/** > * fsflags_cvt > * @table: A table of 32 u32 flags > * @val: a 32 bit value to convert >@@ -1039,6 +1414,7 @@ const struct file_operations gfs2_file_fops = { > > const struct file_operations gfs2_dir_fops = { > .readdir = gfs2_readdir, >+ .xreaddir = gfs2_xreaddir, > .unlocked_ioctl = gfs2_ioctl, > .open = gfs2_open, > .release = gfs2_release, >@@ -1069,6 +1445,7 @@ const struct file_operations gfs2_file_fops_nolock = { > > const struct file_operations gfs2_dir_fops_nolock = { > .readdir = gfs2_readdir, >+ .xreaddir = gfs2_xreaddir, > .unlocked_ioctl = gfs2_ioctl, > .open = gfs2_open, > .release = gfs2_release, >diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c >index db048a8..b4528b8 100644 >--- a/fs/gfs2/inode.c >+++ b/fs/gfs2/inode.c >@@ -1705,7 +1705,8 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, > unlock = 1; > } > >- generic_fillattr(inode, stat); >+ gfs2_getattr_i(ip, stat); >+ > if (unlock) > gfs2_glock_dq_uninit(&gh); > >diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h >index c53c747..9559c10 100644 >--- a/fs/gfs2/inode.h >+++ b/fs/gfs2/inode.h >@@ -93,6 +93,11 @@ err: > return -EIO; > } > >+static inline void gfs2_getattr_i(struct gfs2_inode *ip, struct kstat *stat) >+{ >+ generic_fillattr(&ip->i_inode, stat); >+} >+ > extern struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type, > u64 no_addr, u64 no_formal_ino, > int non_block); >diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h >index 8053573..03e118e 100644 >--- a/fs/gfs2/util.h >+++ b/fs/gfs2/util.h >@@ -11,6 +11,7 @@ > #define __UTIL_DOT_H__ > > #include <linux/mempool.h> >+#include <linux/slab.h> > > #include "incore.h" > >@@ -168,5 +169,45 @@ void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap, > unsigned int bit, int new_value); > int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...); > >+/* >+ * Set of gfs2_alloc, gfs2_realloc and gfs2_free wrapper functions >+ * to user kmalloc/krealloc/vmalloc and kfree/vfree as needed >+ */ >+static __inline__ void* gfs2_alloc(size_t size, gfp_t flags) >+{ >+ void *ptr = NULL; >+ if (size < KMALLOC_MAX_SIZE) >+ ptr = kmalloc(size, flags); >+ if (!ptr) >+ ptr = __vmalloc(size, flags, PAGE_KERNEL); >+ return ptr; >+} >+ >+static __inline__ void* gfs2_realloc(void *p, size_t oldsize, size_t newsize, gfp_t flags) >+{ >+ void *ptr = NULL; >+ >+ if (!is_vmalloc_addr(p)) { >+ if (newsize < KMALLOC_MAX_SIZE) >+ ptr = krealloc(p, newsize, flags); >+ if (ptr) >+ goto out; >+ } >+ ptr = __vmalloc(newsize, flags, PAGE_KERNEL); >+ if (!p) >+ goto out; >+ if (ptr) >+ memcpy(ptr, p, oldsize); >+ /* Frees old buffer even if vmalloc fails */ >+ is_vmalloc_addr(p) ? vfree(p) : kfree(p); >+out: >+ return ptr; >+} >+ >+static __inline__ void gfs2_free(void *p) >+{ >+ is_vmalloc_addr(p) ? vfree(p) : kfree(p); >+} >+ > #endif /* __UTIL_DOT_H__ */ > >diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c >index cbb46c2..48e2a25 100644 >--- a/fs/gfs2/xattr.c >+++ b/fs/gfs2/xattr.c >@@ -11,6 +11,7 @@ > #include <linux/spinlock.h> > #include <linux/completion.h> > #include <linux/buffer_head.h> >+#include <linux/sort.h> > #include <linux/xattr.h> > #include <linux/gfs2_ondisk.h> > #include <asm/uaccess.h> >@@ -18,6 +19,7 @@ > #include "gfs2.h" > #include "incore.h" > #include "acl.h" >+#include "dir.h" > #include "xattr.h" > #include "glock.h" > #include "inode.h" >@@ -73,10 +75,11 @@ static int ea_check_size(struct gfs2_sbd *sdp, unsigned int nsize, size_t dsize) > > typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh, > struct gfs2_ea_header *ea, >- struct gfs2_ea_header *prev, void *private); >+ struct gfs2_ea_header *prev, void *private, >+ unsigned int mask); > > static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, >- ea_call_t ea_call, void *data) >+ ea_call_t ea_call, void *data, unsigned int mask) > { > struct gfs2_ea_header *ea, *prev = NULL; > int error = 0; >@@ -93,7 +96,7 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, > if (!GFS2_EATYPE_VALID(ea->ea_type)) > goto fail; > >- error = ea_call(ip, bh, ea, prev, data); >+ error = ea_call(ip, bh, ea, prev, data, mask); > if (error) > return error; > >@@ -112,7 +115,8 @@ fail: > return -EIO; > } > >-static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) >+static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data, >+ unsigned int mask) > { > struct buffer_head *bh, *eabh; > __be64 *eablk, *end; >@@ -123,7 +127,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) > return error; > > if (!(ip->i_diskflags & GFS2_DIF_EA_INDIRECT)) { >- error = ea_foreach_i(ip, bh, ea_call, data); >+ error = ea_foreach_i(ip, bh, ea_call, data, mask); > goto out; > } > >@@ -145,7 +149,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) > error = gfs2_meta_read(ip->i_gl, bn, DIO_WAIT, &eabh); > if (error) > break; >- error = ea_foreach_i(ip, eabh, ea_call, data); >+ error = ea_foreach_i(ip, eabh, ea_call, data, mask); > brelse(eabh); > if (error) > break; >@@ -164,7 +168,7 @@ struct ea_find { > > static int ea_find_i(struct gfs2_inode *ip, struct buffer_head *bh, > struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, >- void *private) >+ void *private, unsigned mask) > { > struct ea_find *ef = private; > >@@ -199,7 +203,7 @@ static int gfs2_ea_find(struct gfs2_inode *ip, int type, const char *name, > > memset(el, 0, sizeof(struct gfs2_ea_location)); > >- error = ea_foreach(ip, ea_find_i, &ef); >+ error = ea_foreach(ip, ea_find_i, &ef, 0); > if (error > 0) > return 0; > >@@ -223,7 +227,8 @@ static int gfs2_ea_find(struct gfs2_inode *ip, int type, const char *name, > > static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, > struct gfs2_ea_header *ea, >- struct gfs2_ea_header *prev, void *private) >+ struct gfs2_ea_header *prev, void *private, >+ unsigned int mask) > { > int *leave = private; > struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); >@@ -335,7 +340,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, > if (error) > goto out_alloc; > >- error = ea_dealloc_unstuffed(ip, bh, ea, prev, (leave) ? &error : NULL); >+ error = ea_dealloc_unstuffed(ip, bh, ea, prev, (leave) ? &error : NULL, 0); > > gfs2_quota_unhold(ip); > out_alloc: >@@ -361,9 +366,26 @@ static inline unsigned int gfs2_ea_strlen(struct gfs2_ea_header *ea) > } > } > >+static __inline__ int ea_prefix(struct gfs2_ea_header *ea, char *buf, int size) >+{ >+ BUG_ON(size < 9); >+ switch (ea->ea_type) { >+ case GFS2_EATYPE_USR: >+ strncpy(buf, "user.", 5); >+ return 5; >+ case GFS2_EATYPE_SYS: >+ strncpy(buf, "system.", 7); >+ return 7; >+ case GFS2_EATYPE_SECURITY: >+ strncpy(buf, "security.", 9); >+ return 9; >+ } >+ return 0; >+} >+ > static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, > struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, >- void *private) >+ void *private, unsigned int mask) > { > struct ea_list *ei = private; > struct gfs2_ea_request *er = ei->ei_er; >@@ -373,28 +395,14 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, > return 0; > > if (er->er_data_len) { >- char *prefix = NULL; >+ char prefix[9]; > unsigned int l = 0; > char c = 0; > > if (ei->ei_size + ea_size > er->er_data_len) > return -ERANGE; > >- switch (ea->ea_type) { >- case GFS2_EATYPE_USR: >- prefix = "user."; >- l = 5; >- break; >- case GFS2_EATYPE_SYS: >- prefix = "system."; >- l = 7; >- break; >- case GFS2_EATYPE_SECURITY: >- prefix = "security."; >- l = 9; >- break; >- } >- >+ l = ea_prefix(ea, prefix, 9); > BUG_ON(l == 0); > > memcpy(er->er_data + ei->ei_size, prefix, l); >@@ -408,6 +416,169 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, > return 0; > } > >+#define XATTRS_INITIAL_CAPACITY 50 >+ >+void xattrs_free(struct xattr **xattrs, unsigned int count) >+{ >+ int i; >+ for (i=0; i<count; i++) { >+ if (!xattrs[i]) >+ continue; >+ if (xattrs[i]->name) >+ gfs2_free(xattrs[i]->name); >+ >+ if (xattrs[i]->value) >+ gfs2_free(xattrs[i]->value); >+ gfs2_free(xattrs[i]); >+ } >+} >+ >+static inline int xattr_requested(char type, unsigned int mask) >+{ >+ if ((type == GFS2_EATYPE_USR) && (mask & XSTAT_XATTR_USER)) >+ return 1; >+ if ((type == GFS2_EATYPE_SYS) && (mask & XSTAT_XATTR_SYSTEM)) >+ return 1; >+ if ((type == GFS2_EATYPE_SECURITY) && (mask & XSTAT_XATTR_SECURITY)) >+ return 1; >+ return 0; >+} >+ >+static int ea_xdirent_list_i(struct gfs2_inode *ip, struct buffer_head *bh, >+ struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, >+ void *private, unsigned int mask) >+{ >+ struct xdirent *xdent = (struct xdirent *) private; >+ int error = -ENOMEM; >+ char prefix[9]; >+ unsigned int l = 0; >+ char c = 0; >+ struct xattr *xattr = NULL; >+ >+ if (!xattr_requested(ea->ea_type, mask)) >+ return 0; >+ >+ if (ea->ea_type == GFS2_EATYPE_UNUSED) >+ return 0; >+ >+ l = ea_prefix(ea, prefix, 9); >+ BUG_ON(l == 0); >+ >+ /* If we don't have enough xattr pointers, allocate more */ >+ if (xdent->x_xattr_count >= xdent->x_xattr_cap) { >+ unsigned int new_cap = xdent->x_xattr_cap ? >+ xdent->x_xattr_cap * 2 : /* double the cap */ >+ XATTRS_INITIAL_CAPACITY; >+ >+ xdent->x_xattrs = gfs2_realloc(xdent->x_xattrs, >+ xdent->x_xattr_cap * sizeof(struct xattr **), >+ new_cap * sizeof(struct xattr **), >+ GFP_NOFS | __GFP_NOWARN); >+ if (!xdent->x_xattrs) >+ goto out; >+ xdent->x_xattr_cap = new_cap; >+ } >+ >+ xattr = gfs2_alloc(sizeof(struct xattr), GFP_NOFS | __GFP_NOWARN); >+ if (!xattr) >+ goto out; >+ >+ xattr->name = gfs2_alloc(l + ea->ea_name_len + 1, GFP_NOFS | __GFP_NOWARN); >+ if (!xattr->name) >+ goto free_xattr; >+ >+ xattr->value = gfs2_alloc(GFS2_EA_DATA_LEN(ea), GFP_NOFS | __GFP_NOWARN); >+ if (!xattr->value) >+ goto free_xattr; >+ >+ memcpy(xattr->name, prefix, l); >+ memcpy(xattr->name + l, GFS2_EA2NAME(ea), ea->ea_name_len); >+ memcpy(xattr->name + l + ea->ea_name_len, &c, 1); >+ memcpy(xattr->value, GFS2_EA2DATA(ea), GFS2_EA_DATA_LEN(ea)); >+ xattr->value_len = GFS2_EA_DATA_LEN(ea); >+ xdent->x_xattrs[xdent->x_xattr_count++] = xattr; >+ >+ return 0; >+ >+free_xattr: >+ >+ if (xattr && xattr->value) >+ gfs2_free(xattr->value); >+ if (xattr && xattr->name) >+ gfs2_free(xattr->name); >+ if (xattr) >+ gfs2_free(xattr); >+out: >+ return error; >+} >+ >+/* Ordering of this sort: >+ * First set: ip->i_eattr = NULL - i.e no xattrs, these will likely be ignored >+ * Second set: ip->i_diskflags & GFS2_DIF_EA_INDIRECT is false >+ * Third set: all the inodes with indirect blocks >+ */ >+static int compare_i_eblks(const void *a, const void *b) >+{ >+ const struct xdirent *x_a, *x_b; >+ const struct gfs2_inode *i_a, *i_b; >+ >+ x_a = *(const struct xdirent **)a; >+ x_b = *(const struct xdirent **)b; >+ >+ i_a = x_a->x_inode; >+ i_b = x_b->x_inode; >+ >+ /* order ip->i_eattr = NULL cases */ >+ if (!i_a->i_eattr) >+ return -1; >+ if (!i_b->i_eattr) >+ return 1; >+ >+ /* order direct blk xattrs ahead of indirect blk xattrs */ >+ if ((i_a->i_diskflags & GFS2_DIF_EA_INDIRECT) && >+ !(i_b->i_diskflags & GFS2_DIF_EA_INDIRECT)) >+ return 1; >+ >+ if (!(i_a->i_diskflags & GFS2_DIF_EA_INDIRECT) && >+ (i_b->i_diskflags & GFS2_DIF_EA_INDIRECT)) >+ return -1; >+ >+ /* if both are direct blk xattrs or both are indirect blk xattrs */ >+ if (i_a->i_eattr > i_b->i_eattr) >+ return 1; >+ else >+ return -1; >+} >+ >+/** >+ * gfs2_get_inodes_xattr_lists - Get lists of xattrs for a bunch of inodes >+ * @xdents : List of xdirents(inode) for which we need to supply xattrs >+ * @entries: Number of inodes >+ * @mask : Field mask for xattrs >+ * >+ * Returns 0 on success and <0 if an exception occurred. >+ */ >+int gfs2_get_inodes_xattr_lists(struct xdirent **xdents, unsigned int entries, >+ unsigned int mask) >+{ >+ int i, error = 0; >+ /* Sort xdirents in eattr blk# order */ >+ sort(xdents, entries, sizeof(struct xdirent *), compare_i_eblks, NULL); >+ >+ for (i=0; i<entries; i++) { >+ struct gfs2_inode *ip = xdents[i]->x_inode; >+ >+ if (!ip->i_eattr) >+ continue; >+ >+ error = ea_foreach(ip, ea_xdirent_list_i, xdents[i], mask); >+ if (error) >+ goto out; >+ } >+out: >+ return error; >+} >+ > /** > * gfs2_listxattr - List gfs2 extended attributes > * @dentry: The dentry whose inode we are interested in >@@ -437,7 +608,7 @@ ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) > if (ip->i_eattr) { > struct ea_list ei = { .ei_er = &er, .ei_size = 0 }; > >- error = ea_foreach(ip, ea_list_i, &ei); >+ error = ea_foreach(ip, ea_list_i, &ei, 0); > if (!error) > error = ei.ei_size; > } >@@ -918,7 +1089,7 @@ static int ea_set_simple_alloc(struct gfs2_inode *ip, > > static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh, > struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, >- void *private) >+ void *private, unsigned int mask) > { > struct ea_set *es = private; > unsigned int size; >@@ -1055,7 +1226,7 @@ static int ea_set_i(struct gfs2_inode *ip, int type, const char *name, > es.es_er = &er; > es.es_el = el; > >- error = ea_foreach(ip, ea_set_simple, &es); >+ error = ea_foreach(ip, ea_set_simple, &es, 0); > if (error > 0) > return 0; > if (error) >@@ -1465,7 +1636,7 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip) > if (error) > return error; > >- error = ea_foreach(ip, ea_dealloc_unstuffed, NULL); >+ error = ea_foreach(ip, ea_dealloc_unstuffed, NULL, 0); > if (error) > goto out_quota; > >diff --git a/fs/gfs2/xattr.h b/fs/gfs2/xattr.h >index d392f83..fa672fe 100644 >--- a/fs/gfs2/xattr.h >+++ b/fs/gfs2/xattr.h >@@ -10,6 +10,8 @@ > #ifndef __EATTR_DOT_H__ > #define __EATTR_DOT_H__ > >+#include "dir.h" >+ > struct gfs2_inode; > struct iattr; > >@@ -56,6 +58,9 @@ struct gfs2_ea_location { > extern int __gfs2_xattr_set(struct inode *inode, const char *name, > const void *value, size_t size, > int flags, int type); >+extern void xattrs_free(struct xattr **xattrs, unsigned int count); >+extern int gfs2_get_inodes_xattr_lists(struct xdirent **xdents, unsigned int entries, >+ unsigned int mask); > extern ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size); > extern int gfs2_ea_dealloc(struct gfs2_inode *ip); > >diff --git a/fs/readdir.c b/fs/readdir.c >index 5e69ef5..74460df 100644 >--- a/fs/readdir.c >+++ b/fs/readdir.c >@@ -143,6 +143,105 @@ struct getdents_callback { > int error; > }; > >+static size_t get_xdirent_size(const struct xdirent_info *xinfo) >+{ >+ int i; >+ /* Start with the base size */ >+ size_t size = sizeof(struct linux_xdirent); >+ /* Account for the various variable length fields >+ * starting with dirent name. Note that one trailing >+ * '\0' is already accounted for by the xd_blob field >+ * in struct linux_xdirent >+ */ >+ size += xinfo->xi_namelen; >+ if (!xinfo->xi_xattr_count) >+ return size; /* No xattrs to worry about */ >+ for (i=0; i<xinfo->xi_xattr_count; i++) { >+ struct xattr *xattr = xinfo->xi_xattrs[i]; >+ size += sizeof(size_t); /* for xdirent_xattr.xa_value_len */ >+ size += strlen(xattr->name) + 1; >+ size += xattr->value_len; >+ } >+ return size; >+} >+ >+static int xfill_variables(struct linux_xdirent __user *lxd, >+ const struct xdirent_info *xinfo) >+{ >+ int error = -EINVAL, i; >+ struct xdirent_blob __user *xblob; >+ struct xdirent_xattr __user *xx; >+ >+ xblob = &lxd->xd_blob; >+ >+ if (__put_user(xinfo->xi_xattr_count, &xblob->xb_xattr_count)) >+ goto out; >+ >+ if (copy_to_user(xblob->xb_blob, xinfo->xi_name, xinfo->xi_namelen)) >+ goto out; >+ if (__put_user(0, xblob->xb_blob + xinfo->xi_namelen)) >+ goto out; >+ >+ xx = (struct xdirent_xattr __user *)(xblob->xb_blob + xinfo->xi_namelen + 1); >+ >+ for (i=0; i< xinfo->xi_xattr_count; i++) { >+ struct xattr *xattr = xinfo->xi_xattrs[i]; >+ int namlen = strlen(xattr->name); >+ >+ if (__put_user(xattr->value_len, &xx->xa_value_len)) >+ goto out; >+ if (copy_to_user(xx->xa_name_val, xattr->name, namlen)) >+ goto out; >+ if (__put_user(0, xx->xa_name_val + namlen)) >+ goto out; >+ if (copy_to_user(xx->xa_name_val + namlen + 1, xattr->value, >+ xattr->value_len)) >+ goto out; >+ xx = (struct xdirent_xattr __user *) >+ ((char *)xx + sizeof(xx->xa_value_len) >+ + namlen + 1 + xattr->value_len); >+ } >+ error = 0; >+out: >+ return error; >+} >+ >+static int xfilldir(void *__opaque, const struct xdirent_info *xinfo) >+{ >+ struct xdirent_buf *xbuf = (struct xdirent_buf *) __opaque; >+ struct linux_xdirent __user *lxd; >+ int error = -EOVERFLOW; >+ size_t entsize; >+ >+ /* Before proceeding any further, check that the dirent will >+ * fit in its entirety in the remaining space of the user >+ * buffer >+ */ >+ entsize = get_xdirent_size(xinfo); >+ if ((xbuf->xb_count - xbuf->xb_used) < entsize) >+ goto out; >+ >+ error = -EINVAL; >+ lxd = (struct linux_xdirent __user *)(xbuf->xb_buf + xbuf->xb_used); >+ if (__put_user(xinfo->xi_ino, &lxd->xd_ino)) >+ goto out; >+ if (__put_user(xinfo->xi_type, &lxd->xd_type)) >+ goto out; >+ if (__put_user(xinfo->xi_offset, &lxd->xd_off)) >+ goto out; >+ if (__put_user(entsize, &lxd->xd_reclen)) >+ goto out; >+ error = xstat_set_result((struct kstat *)&xinfo->xi_stat, &lxd->xd_stat); >+ if (error) >+ goto out; >+ error = xfill_variables(lxd, xinfo); >+ if (error) >+ goto out; >+ xbuf->xb_used += entsize; >+out: >+ return error; >+} >+ > static int filldir(void * __buf, const char * name, int namlen, loff_t offset, > u64 ino, unsigned int d_type) > { >@@ -220,6 +319,52 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd, > return error; > } > >+SYSCALL_DEFINE5(xgetdents, unsigned int, fd, unsigned, flags, unsigned int, mask, >+ void __user *, buf, unsigned int, count) >+{ >+ struct file *file; >+ struct inode *inode; >+ int fput_needed; >+ int error = -ENOTDIR; >+ >+ if (!access_ok(VERIFY_WRITE, buf, count)) >+ return -EFAULT; >+ >+ file = fget_light(fd, &fput_needed); >+ if (!file) >+ return -EBADF; >+ >+ inode = file->f_path.dentry->d_inode; >+ >+ if (!file->f_op || !file->f_op->xreaddir) >+ goto out; >+ >+ error = security_file_permission(file, MAY_READ); >+ if (error) >+ goto out; >+ >+ error = mutex_lock_killable(&inode->i_mutex); >+ if (error) >+ goto out; >+ >+ error = -ENOENT; >+ if (!IS_DEADDIR(inode)) { >+ struct xdirent_buf xbuf; >+ xbuf.xb_buf = buf; >+ xbuf.xb_used = 0; >+ xbuf.xb_count = count; >+ error = file->f_op->xreaddir(file, flags, mask, count, &xbuf, xfilldir); >+ if (!error || error == -EOVERFLOW) >+ error = xbuf.xb_used; >+ >+ file_accessed(file); >+ } >+ mutex_unlock(&inode->i_mutex); >+out: >+ fput_light(file, fput_needed); >+ return error; >+} >+ > struct getdents_callback64 { > struct linux_dirent64 __user * current_dir; > struct linux_dirent64 __user * previous; >diff --git a/fs/stat.c b/fs/stat.c >index 5303f40..60376d3 100644 >--- a/fs/stat.c >+++ b/fs/stat.c >@@ -635,7 +635,7 @@ static int xstat_get_params(unsigned int mask, struct xstat __user *buffer, > * Otherwise we copy the extended stats to userspace and return the amount of > * data written into the buffer (or -EFAULT). > */ >-static long xstat_set_result(struct kstat *stat, struct xstat __user *buffer) >+long xstat_set_result(struct kstat *stat, struct xstat __user *buffer) > { > u32 mask = stat->result_mask, gran = stat->tv_granularity; > >@@ -685,6 +685,8 @@ static long xstat_set_result(struct kstat *stat, struct xstat __user *buffer) > return 0; > } > >+EXPORT_SYMBOL(xstat_set_result); >+ > /* > * System call to get extended stats by path > */ >diff --git a/include/linux/fs.h b/include/linux/fs.h >index 44c6c84..9d164ec 100644 >--- a/include/linux/fs.h >+++ b/include/linux/fs.h >@@ -1505,6 +1505,8 @@ int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); > * to have different dirent layouts depending on the binary type. > */ > typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); >+typedef int (*xfilldir_t)(void *, const struct xdirent_info *); >+ > struct block_device_operations; > > /* These macros are for out of kernel modules to test that >@@ -1521,6 +1523,7 @@ struct file_operations { > ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); > ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); > int (*readdir) (struct file *, void *, filldir_t); >+ int (*xreaddir) (struct file *, unsigned int, unsigned int, size_t, void *, xfilldir_t); > unsigned int (*poll) (struct file *, struct poll_table_struct *); > long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); > long (*compat_ioctl) (struct file *, unsigned int, unsigned long); >diff --git a/include/linux/stat.h b/include/linux/stat.h >index 552e047..e18d107 100644 >--- a/include/linux/stat.h >+++ b/include/linux/stat.h >@@ -18,6 +18,7 @@ > #include <linux/types.h> > #include <linux/time.h> > #include <linux/uidgid.h> >+#include <linux/xattr.h> > > struct kstat { > u32 query_flags; /* operational flags */ >@@ -46,4 +47,23 @@ struct kstat { > unsigned char volume_id[16]; /* volume identifier */ > }; > >+long xstat_set_result(struct kstat *stat, struct xstat __user *buffer); >+ >+struct xdirent_buf { >+ void __user *xb_buf; >+ size_t xb_count; >+ size_t xb_used; >+}; >+ >+struct xdirent_info { >+ const char *xi_name; >+ int xi_namelen; >+ u64 xi_ino; >+ u64 xi_offset; >+ char xi_type; >+ unsigned int xi_xattr_count; >+ struct kstat xi_stat; >+ struct xattr **xi_xattrs; >+}; >+ > #endif >diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h >index 2907352..44a5aae 100644 >--- a/include/uapi/linux/stat.h >+++ b/include/uapi/linux/stat.h >@@ -90,6 +90,13 @@ > #define XSTAT_VOLUME_ID 0x00008000U /* want/got st_volume_id */ > #define XSTAT_ALL_STATS 0x0000ffffU /* all supported stats */ > >+/* xattr request flags */ >+#define XSTAT_XATTR_USER 0x00010000U /* user.* xattrs */ >+#define XSTAT_XATTR_SYSTEM 0x00020000U /* system.* xattrs */ >+#define XSTAT_XATTR_SECURITY 0x00040000U /* security.* xattrs */ >+#define XSTAT_XATTR_POSIX_ACL 0x00080000U /* posix acl xattrs */ >+#define XSTAT_ALL_XATTRS 0x00ff0000U /* all xattrs */ >+ > /* > * Extended stat structures > */ >@@ -152,4 +159,29 @@ struct xstat { > #define XSTAT_INFO_SYSTEM 0x00001000U /* File is marked system (DOS+) */ > #define XSTAT_INFO_ARCHIVE 0x00002000U /* File is marked archive (DOS+) */ > >+struct xdirent_xattr { >+ size_t xa_value_len; /* length of value field */ >+ char xa_name_val[1]; /* name/value pair, name is NULL terminated and >+ * value is xa_value_len in length */ >+}; >+ >+/* >+ * xb_blob: first contains NULL terminated name, followed by struct xdirent_xattr >+ * objects packed together. >+ */ >+struct xdirent_blob { >+ unsigned int xb_xattr_count; >+ char xb_blob[1]; /* contains variable length data like >+ * NULL-terminated name, xattrs etc */ >+}; >+ >+struct linux_xdirent { >+ unsigned long xd_ino; >+ char xd_type; >+ unsigned long xd_off; >+ struct xstat xd_stat; >+ unsigned long xd_reclen; >+ struct xdirent_blob xd_blob; >+}; >+ > #endif /* _UAPI_LINUX_STAT_H */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 850426
:
605960
|
617073
|
625592
|
678841
|
680222
|
680282
|
708389
|
731269
|
731270
|
731272
|
731273
|
731274
|
731278
|
731279
|
732739
|
732740
|
732845
|
834840
|
853502
|
909528
|
909529
|
909534
|
912745
|
917238
|
917239
|
920895
|
920896
|
920897
|
920898
|
920899
|
920902
|
920903
|
947987