mirror of
https://github.com/ceph/ceph
synced 2025-01-12 14:10:27 +00:00
chain_xattr: add chain_getxattr_buf
Otherwise callers need to implement buffer doubling in a lot of cases, which is error prone. Signed-off-by: Samuel Just <sjust@redhat.com>
This commit is contained in:
parent
755c685f2d
commit
c7db303028
@ -173,6 +173,35 @@ int chain_getxattr(const char *fn, const char *name, void *val, size_t size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int chain_getxattr_buf(const char *fn, const char *name, bufferptr *bp)
|
||||
{
|
||||
size_t size = 1024; // Initial
|
||||
while (1) {
|
||||
bufferptr buf(size);
|
||||
int r = chain_getxattr(
|
||||
fn,
|
||||
name,
|
||||
buf.c_str(),
|
||||
size);
|
||||
if (r > 0) {
|
||||
buf.set_length(r);
|
||||
if (bp)
|
||||
bp->swap(buf);
|
||||
return r;
|
||||
} else if (r == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
if (r == -ERANGE) {
|
||||
size *= 2;
|
||||
} else {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(0 == "unreachable");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int chain_fgetxattr_len(int fd, const char *name)
|
||||
{
|
||||
int i = 0, total = 0;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "common/xattr.h"
|
||||
#include "include/assert.h"
|
||||
#include "include/buffer.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -80,6 +81,7 @@ static inline int sys_fremovexattr(int fd, const char *name)
|
||||
// wrappers to chain large values across multiple xattrs
|
||||
|
||||
int chain_getxattr(const char *fn, const char *name, void *val, size_t size);
|
||||
int chain_getxattr_buf(const char *fn, const char *name, bufferptr *bp);
|
||||
int chain_fgetxattr(int fd, const char *name, void *val, size_t size);
|
||||
|
||||
int get_xattr_block_size(size_t size);
|
||||
|
Loading…
Reference in New Issue
Block a user