From: Andrew Price Date: Tue, 29 Mar 2016 12:26:22 +0100 Subject: [Cluster-devel] [PATCH 1/3] libgfs2: New function lgfs2_rindex_read_one() Message-ID: <1459250784-27105-1-git-send-email-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Add a simple function to read an rindex entry into a set of resource groups. Signed-off-by: Andrew Price --- gfs2/libgfs2/libgfs2.h | 2 ++ gfs2/libgfs2/rgrp.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h index 7c87884..d6c54b3 100644 --- a/gfs2/libgfs2/libgfs2.h +++ b/gfs2/libgfs2/libgfs2.h @@ -177,6 +177,7 @@ struct gfs2_bitmap }; struct gfs2_sbd; +struct gfs2_inode; typedef struct _lgfs2_rgrps *lgfs2_rgrps_t; struct rgrp_tree { @@ -196,6 +197,7 @@ extern lgfs2_rgrps_t lgfs2_rgrps_init(struct gfs2_sbd *sdp, uint64_t align, uint extern void lgfs2_rgrps_free(lgfs2_rgrps_t *rgs); extern uint64_t lgfs2_rindex_entry_new(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry, uint64_t addr, uint32_t len); extern unsigned lgfs2_rindex_read_fd(int fd, lgfs2_rgrps_t rgs); +extern const struct gfs2_rindex *lgfs2_rindex_read_one(struct gfs2_inode *rip, lgfs2_rgrps_t rgs, unsigned i); extern uint64_t lgfs2_rgrp_align_addr(const lgfs2_rgrps_t rgs, uint64_t addr); extern uint32_t lgfs2_rgrp_align_len(const lgfs2_rgrps_t rgs, uint32_t len); extern unsigned lgfs2_rgsize_for_data(uint64_t blksreq, unsigned bsize); diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c index 766bdfc..7066a5c 100644 --- a/gfs2/libgfs2/rgrp.c +++ b/gfs2/libgfs2/rgrp.c @@ -430,6 +430,38 @@ unsigned lgfs2_rindex_read_fd(int fd, lgfs2_rgrps_t rgs) } /** + * Read a rindex entry into a set of resource groups + * rip: The inode of the rindex file + * rgs: The set of resource groups. + * i: The index of the entry to read from the rindex file + * Returns the new rindex entry added to the set or NULL on error with errno + * set. + */ +const struct gfs2_rindex *lgfs2_rindex_read_one(struct gfs2_inode *rip, lgfs2_rgrps_t rgs, unsigned i) +{ + uint64_t off = i * sizeof(struct gfs2_rindex); + char buf[sizeof(struct gfs2_rindex)]; + struct gfs2_rindex ri; + lgfs2_rgrp_t rg; + int ret; + + errno = EINVAL; + if (rip == NULL || rgs == NULL) + return NULL; + + ret = gfs2_readi(rip, buf, off, sizeof(struct gfs2_rindex)); + if (ret != sizeof(struct gfs2_rindex)) + return NULL; + + gfs2_rindex_in(&ri, buf); + rg = lgfs2_rgrps_append(rgs, &ri); + if (rg == NULL) + return NULL; + + return &rg->ri; +} + +/** * Free a set of resource groups created with lgfs2_rgrps_append() etc. This * does not write any dirty buffers to disk. See lgfs2_rgrp_write(). * rgs: A pointer to the set of resource groups to be freed. -- 2.4.3