From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 09/14] libgfs2: Add a lgfs2_rindex_read_fd() function
Date: Thu, 3 Apr 2014 16:12:42 +0100 [thread overview]
Message-ID: <1396537967-12399-10-git-send-email-anprice@redhat.com> (raw)
In-Reply-To: <1396537967-12399-1-git-send-email-anprice@redhat.com>
gfs2_grow opens the rindex file through the metafs so it needs a way to
populate a lgfs2_rgrps_t with existing resource groups. Add
lgfs2_rindex_read_fd() to read in the rindex entries from a fd.
Also const-ify the return types of lgfs2_rgrp_index() and
lgfs2_rgrp_rgrp() to warn users that they shouldn't change the contents
of libgfs2-managed data.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/libgfs2/libgfs2.h | 5 +++--
gfs2/libgfs2/rgrp.c | 43 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index b70c36d..455f01d 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -192,14 +192,15 @@ typedef struct _lgfs2_rgrps *lgfs2_rgrps_t;
extern lgfs2_rgrps_t lgfs2_rgrps_init(unsigned bsize, uint64_t devlen, uint64_t align, uint64_t offset);
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 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);
extern uint32_t lgfs2_rgrps_plan(const lgfs2_rgrps_t rgs, uint64_t space, uint32_t tgtsize);
extern lgfs2_rgrp_t lgfs2_rgrps_append(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry);
extern int lgfs2_rgrp_write(lgfs2_rgrps_t rgs, int fd, lgfs2_rgrp_t rg);
-extern struct gfs2_rindex *lgfs2_rgrp_index(lgfs2_rgrp_t rg);
-extern struct gfs2_rgrp *lgfs2_rgrp_rgrp(lgfs2_rgrp_t rg);
+extern const struct gfs2_rindex *lgfs2_rgrp_index(lgfs2_rgrp_t rg);
+extern const struct gfs2_rgrp *lgfs2_rgrp_rgrp(lgfs2_rgrp_t rg);
extern lgfs2_rgrp_t lgfs2_rgrp_first(lgfs2_rgrps_t rgs);
extern lgfs2_rgrp_t lgfs2_rgrp_last(lgfs2_rgrps_t rgs);
extern lgfs2_rgrp_t lgfs2_rgrp_next(lgfs2_rgrp_t rg);
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index 02ab450..cae7a32 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -275,8 +275,8 @@ uint32_t lgfs2_rgrp_align_len(const lgfs2_rgrps_t rgs, uint32_t len)
* rgs: The resource groups descriptor
* space: The number of remaining blocks to be allocated
* tgtsize: The target resource group size in blocks
- * Returns the larger of the calculated resource group sizes or 0 if the
- * smaller would be less than GFS2_MIN_RGSIZE.
+ * Returns the larger of the calculated resource group sizes, in blocks, or 0
+ * if the smaller would be less than GFS2_MIN_RGSIZE.
*/
uint32_t lgfs2_rgrps_plan(const lgfs2_rgrps_t rgs, uint64_t space, uint32_t tgtsize)
{
@@ -361,6 +361,41 @@ lgfs2_rgrps_t lgfs2_rgrps_init(unsigned bsize, uint64_t devlen, uint64_t align,
}
/**
+ * Populate a set of resource groups from a gfs2 rindex file.
+ * fd: An open file descriptor for the rindex file.
+ * rgs: The set of resource groups.
+ * Returns the number of resource groups added to the set or 0 on error with
+ * errno set.
+ */
+unsigned lgfs2_rindex_read_fd(int fd, lgfs2_rgrps_t rgs)
+{
+ unsigned count = 0;
+ char buf[sizeof(struct gfs2_rindex)];
+
+ errno = EINVAL;
+ if (fd < 0 || rgs == NULL)
+ return 0;
+
+ while (1) {
+ lgfs2_rgrp_t rg;
+ struct gfs2_rindex ri;
+ ssize_t ret = read(fd, buf, sizeof(struct gfs2_rindex));
+ if (ret == 0)
+ break;
+
+ if (ret != sizeof(struct gfs2_rindex))
+ return 0;
+
+ gfs2_rindex_in(&ri, buf);
+ rg = lgfs2_rgrps_append(rgs, &ri);
+ if (rg == NULL)
+ return 0;
+ count++;
+ }
+ return count;
+}
+
+/**
* 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.
@@ -428,7 +463,7 @@ uint64_t lgfs2_rindex_entry_new(lgfs2_rgrps_t rgs, struct gfs2_rindex *ri, uint6
/**
* Return the rindex structure relating to a a resource group.
*/
-struct gfs2_rindex *lgfs2_rgrp_index(lgfs2_rgrp_t rg)
+const struct gfs2_rindex *lgfs2_rgrp_index(lgfs2_rgrp_t rg)
{
return &rg->ri;
}
@@ -436,7 +471,7 @@ struct gfs2_rindex *lgfs2_rgrp_index(lgfs2_rgrp_t rg)
/**
* Return the rgrp structure relating to a a resource group.
*/
-struct gfs2_rgrp *lgfs2_rgrp_rgrp(lgfs2_rgrp_t rg)
+const struct gfs2_rgrp *lgfs2_rgrp_rgrp(lgfs2_rgrp_t rg)
{
return &rg->rg;
}
--
1.8.5.3
next prev parent reply other threads:[~2014-04-03 15:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-03 15:12 [Cluster-devel] [PATCH 00/14] gfs2_grow and libgfs2 rgrp API improvements Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 01/14] mkfs.gfs2: Make dev a member of mkfs_opts Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 02/14] libgfs2: Add lgfs2_space_for_data() Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 03/14] libgfs2: Don't try to read more than IOV_MAX iovecs Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 04/14] mkfs.gfs2: Fix the resource group layout strategy, again Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 05/14] libgfs2: Don't call gfs2_blk2rgrpd in gfs2_set_bitmap Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 06/14] libgfs2: Add abstractions for rgrp tree traversal Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 07/14] libgfs2: Split out the rindex calculation from lgfs2_rgrp_append Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 08/14] libgfs2: Consolidate rgrp_tree and bitstruct allocations Andrew Price
2014-04-03 15:12 ` Andrew Price [this message]
2014-04-03 15:12 ` [Cluster-devel] [PATCH 10/14] libgfs2: Const-ify the 'ri' argument to gfs2_rindex_out Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 11/14] libgfs2: Fix off-by-one in lgfs2_rgrps_plan Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 12/14] libgfs2: Stick to the (rgrp) plan in lgfs2_rindex_entry_new Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 13/14] gfs2_grow: Migrate to the new resource group API Andrew Price
2014-04-03 15:12 ` [Cluster-devel] [PATCH 14/14] gfs2_grow: Add stripe alignment Andrew Price
2014-04-07 15:15 ` [Cluster-devel] [PATCH 00/14] gfs2_grow and libgfs2 rgrp API improvements Bob Peterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1396537967-12399-10-git-send-email-anprice@redhat.com \
--to=anprice@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).