gfs2-utils: master - libgfs2: Introduce struct lgfs2_rbm
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=9ac31196...
Commit: 9ac311967c3208d1f482628ebfbf38e2c7651229
Parent: 04aa942a2e4967974869d845be6b12850a210928
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Jun 13 15:45:07 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Sep 1 11:26:05 2014 +0100
libgfs2: Introduce struct lgfs2_rbm
Add struct lgfs2_rbm, which is similar to struct gfs2_rbm in the kernel,
in order to support the coming work on extent allocation in libgfs2.
This structure and its supporting functions are added to a new private
header file rather than libgfs2.h until we have reason to export it.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/Makefile.am | 2 +-
gfs2/libgfs2/rgrp.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++
gfs2/libgfs2/rgrp.h | 29 ++++++++++++++++++++
3 files changed, 97 insertions(+), 1 deletions(-)
diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index 4af27be..1ce8c13 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -5,7 +5,7 @@ BUILT_SOURCES = parser.h lexer.h
AM_LFLAGS = --header-file=lexer.h
AM_YFLAGS = -d
-noinst_HEADERS = libgfs2.h lang.h config.h
+noinst_HEADERS = libgfs2.h lang.h config.h rgrp.h
noinst_LTLIBRARIES = libgfs2.la
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index 56b73ae..dd8811b 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -1,12 +1,14 @@
#include "clusterautoconfig.h"
#include <inttypes.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libgfs2.h"
+#include "rgrp.h"
#define RG_SYNC_TOLERANCE 1000
@@ -589,3 +591,68 @@ lgfs2_rgrp_t lgfs2_rgrp_last(lgfs2_rgrps_t rgs)
{
return (lgfs2_rgrp_t)osi_last(&rgs->root);
}
+
+/**
+ * gfs2_rbm_from_block - Set the rbm based upon rgd and block number
+ * @rbm: The rbm with rgd already set correctly
+ * @block: The block number (filesystem relative)
+ *
+ * This sets the bi and offset members of an rbm based on a
+ * resource group and a filesystem relative block number. The
+ * resource group must be set in the rbm on entry, the bi and
+ * offset members will be set by this function.
+ *
+ * Returns: 0 on success, or non-zero with errno set
+ */
+static int lgfs2_rbm_from_block(struct lgfs2_rbm *rbm, uint64_t block)
+{
+ uint64_t rblock = block - rbm->rgd->ri.ri_data0;
+ struct gfs2_sbd *sdp = rbm_bi(rbm)->bi_bh->sdp;
+
+ if (rblock > UINT_MAX) {
+ errno = EINVAL;
+ return 1;
+ }
+ if (block >= rbm->rgd->ri.ri_data0 + rbm->rgd->ri.ri_data) {
+ errno = E2BIG;
+ return 1;
+ }
+
+ rbm->bii = 0;
+ rbm->offset = (uint32_t)(rblock);
+ /* Check if the block is within the first block */
+ if (rbm->offset < (rbm_bi(rbm)->bi_len * GFS2_NBBY))
+ return 0;
+
+ /* Adjust for the size diff between gfs2_meta_header and gfs2_rgrp */
+ rbm->offset += (sizeof(struct gfs2_rgrp) -
+ sizeof(struct gfs2_meta_header)) * GFS2_NBBY;
+ rbm->bii = rbm->offset / sdp->sd_blocks_per_bitmap;
+ rbm->offset -= rbm->bii * sdp->sd_blocks_per_bitmap;
+ return 0;
+}
+
+/**
+ * lgfs2_rbm_incr - increment an rbm structure
+ * @rbm: The rbm with rgd already set correctly
+ *
+ * This function takes an existing rbm structure and increments it to the next
+ * viable block offset.
+ *
+ * Returns: If incrementing the offset would cause the rbm to go past the
+ * end of the rgrp, true is returned, otherwise false.
+ *
+ */
+static int lgfs2_rbm_incr(struct lgfs2_rbm *rbm)
+{
+ if (rbm->offset + 1 < (rbm_bi(rbm)->bi_len * GFS2_NBBY)) { /* in the same bitmap */
+ rbm->offset++;
+ return 0;
+ }
+ if (rbm->bii == rbm->rgd->ri.ri_length - 1) /* at the last bitmap */
+ return 1;
+
+ rbm->offset = 0;
+ rbm->bii++;
+ return 0;
+}
diff --git a/gfs2/libgfs2/rgrp.h b/gfs2/libgfs2/rgrp.h
new file mode 100644
index 0000000..99c52d3
--- /dev/null
+++ b/gfs2/libgfs2/rgrp.h
@@ -0,0 +1,29 @@
+#ifndef __RGRP_DOT_H__
+#define __RGRP_DOT_H__
+
+#include "libgfs2.h"
+
+struct lgfs2_rbm {
+ lgfs2_rgrp_t rgd;
+ uint32_t offset; /* The offset is bitmap relative */
+ unsigned bii; /* Bitmap index */
+};
+
+static inline struct gfs2_bitmap *rbm_bi(const struct lgfs2_rbm *rbm)
+{
+ return rbm->rgd->bits + rbm->bii;
+}
+
+static inline uint64_t lgfs2_rbm_to_block(const struct lgfs2_rbm *rbm)
+{
+ return rbm->rgd->ri.ri_data0 + (rbm_bi(rbm)->bi_start * GFS2_NBBY) +
+ rbm->offset;
+}
+
+static inline int lgfs2_rbm_eq(const struct lgfs2_rbm *rbm1, const struct lgfs2_rbm *rbm2)
+{
+ return (rbm1->rgd == rbm2->rgd) && (rbm1->bii == rbm2->bii) &&
+ (rbm1->offset == rbm2->offset);
+}
+
+#endif /* __RGRP_DOT_H__ */
9 years, 8 months
gfs2-utils: master - libgfs2: Fix an impossible loop condition in gfs2_rgrp_read
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=04aa942a...
Commit: 04aa942a2e4967974869d845be6b12850a210928
Parent: 6672ca092b33897d527b1ae9bbef774513ca3b66
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Sat Aug 30 00:06:28 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Sep 1 11:11:54 2014 +0100
libgfs2: Fix an impossible loop condition in gfs2_rgrp_read
Correct a loop which expects an unsigned int to become negative.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/rgrp.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index e929846..56b73ae 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -131,10 +131,10 @@ uint64_t gfs2_rgrp_read(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
bi->bi_bh = bhs[x];
if (gfs2_check_meta(bi->bi_bh, mtype)) {
unsigned err = x;
- for (; x >= 0; x--) {
+ do {
brelse(rgd->bits[x].bi_bh);
rgd->bits[x].bi_bh = NULL;
- }
+ } while (x-- != 0);
free(bhs);
return rgd->ri.ri_addr + err;
}
9 years, 8 months
gfs2-utils: master - libgfs2: Move bitmap buffers inside struct gfs2_bitmap
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=6672ca09...
Commit: 6672ca092b33897d527b1ae9bbef774513ca3b66
Parent: a5fb90e9012bda93be4c5a53f3e8fe0cf2922a9a
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Jun 12 03:54:15 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Sep 1 11:09:29 2014 +0100
libgfs2: Move bitmap buffers inside struct gfs2_bitmap
Keeping an array of buffers alongside the array of bitmaps meant some
extra management and bookkeeping for arrays of buffer pointers. Move the
buffer pointers into the bitmap structures.
The only downside to this is that reading resource groups gets a little
more complicated and an intermediate array of buffer pointers is created
in gfs2_rgrp_read to make sure we can still use vector i/o. Fortunately
this doesn't cause any noticeable slowdown.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 42 +++++++++++---------------
gfs2/edit/journal.c | 6 ++--
gfs2/fsck/fs_recovery.c | 2 +-
gfs2/fsck/initialize.c | 15 ++++-----
gfs2/fsck/metawalk.c | 10 ++----
gfs2/fsck/pass5.c | 9 ++---
gfs2/fsck/rgrepair.c | 14 ++++-----
gfs2/fsck/util.c | 2 +-
gfs2/libgfs2/fs_bits.c | 10 ++++--
gfs2/libgfs2/fs_geometry.c | 6 ++--
gfs2/libgfs2/fs_ops.c | 16 +++++-----
gfs2/libgfs2/libgfs2.h | 2 +-
gfs2/libgfs2/rgrp.c | 70 +++++++++++++++++++++---------------------
gfs2/libgfs2/structures.c | 2 +-
14 files changed, 98 insertions(+), 108 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 87bec8c..61ed320 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -142,16 +142,18 @@ static void convert_bitmaps(struct gfs2_sbd *sdp, struct rgrp_tree *rg)
ri = &rg->ri;
for (blk = 0; blk < ri->ri_length; blk++) {
+ struct gfs2_bitmap *bi;
x = (blk) ? sizeof(struct gfs2_meta_header) :
sizeof(struct gfs2_rgrp);
+ bi = &rg->bits[blk];
for (; x < sdp->bsize; x++)
for (y = 0; y < GFS2_NBBY; y++) {
- state = (rg->bh[blk]->b_data[x] >>
+ state = (bi->bi_bh->b_data[x] >>
(GFS2_BIT_SIZE * y)) & 0x03;
if (state == 0x02) {/* unallocated metadata state invalid */
- rg->bh[blk]->b_data[x] &= ~(0x02 << (GFS2_BIT_SIZE * y));
- bmodified(rg->bh[blk]);
+ bi->bi_bh->b_data[x] &= ~(0x02 << (GFS2_BIT_SIZE * y));
+ bmodified(bi->bi_bh);
}
}
}
@@ -188,7 +190,7 @@ static int convert_rgs(struct gfs2_sbd *sbp)
sbp->dinodes_alloced += rgd1->rg_useddi;
convert_bitmaps(sbp, rgd);
/* Write the updated rgrp to the gfs2 buffer */
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
rgs++;
if (rgs % 100 == 0) {
printf(".");
@@ -969,8 +971,8 @@ static int next_rg_meta(struct rgrp_tree *rgd, uint64_t *block, int first)
}
for (; i < length; i++){
bits = &rgd->bits[i];
- blk = gfs2_bitfit((unsigned char *)rgd->bh[i]->b_data +
- bits->bi_offset, bits->bi_len, blk, GFS2_BLKST_DINODE);
+ blk = gfs2_bitfit((uint8_t *)bits->bi_bh->b_data + bits->bi_offset,
+ bits->bi_len, blk, GFS2_BLKST_DINODE);
if(blk != BFITNOENT){
*block = blk + (bits->bi_start * GFS2_NBBY) +
rgd->ri.ri_data0;
@@ -1073,16 +1075,17 @@ static int inode_renumber(struct gfs2_sbd *sbp, uint64_t root_inode_addr, osi_li
byte_bit = (block - rgd->ri.ri_data0) % GFS2_NBBY;
/* Now figure out which bitmap block the byte is on */
for (blk = 0; blk < rgd->ri.ri_length; blk++) {
+ struct gfs2_bitmap *bi = &rgd->bits[blk];
/* figure out offset of first bitmap byte for this map: */
buf_offset = (blk) ? sizeof(struct gfs2_meta_header) :
sizeof(struct gfs2_rgrp);
/* if it's on this page */
if (buf_offset + bitmap_byte < sbp->bsize) {
- rgd->bh[blk]->b_data[buf_offset + bitmap_byte] &=
+ bi->bi_bh->b_data[buf_offset + bitmap_byte] &=
~(0x03 << (GFS2_BIT_SIZE * byte_bit));
- rgd->bh[blk]->b_data[buf_offset + bitmap_byte] |=
+ bi->bi_bh->b_data[buf_offset + bitmap_byte] |=
(0x01 << (GFS2_BIT_SIZE * byte_bit));
- bmodified(rgd->bh[blk]);
+ bmodified(bi->bi_bh);
break;
}
bitmap_byte -= (sbp->bsize - buf_offset);
@@ -1854,29 +1857,20 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)
rgd->rg.rg_free = rgd->ri.ri_data;
rgd->ri.ri_bitbytes = rgd->ri.ri_data / GFS2_NBBY;
- if(!(rgd->bh = (struct gfs2_buffer_head **)
- malloc(rgd->ri.ri_length *
- sizeof(struct gfs2_buffer_head *))))
- return -1;
- if(!memset(rgd->bh, 0, rgd->ri.ri_length *
- sizeof(struct gfs2_buffer_head *))) {
- free(rgd->bh);
- return -1;
- }
- for (x = 0; x < rgd->ri.ri_length; x++) {
- rgd->bh[x] = bget(sdp, rgd->ri.ri_addr + x);
- memset(rgd->bh[x]->b_data, 0, sdp->bsize);
- }
if (gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, rgd)) {
log_crit(_("gfs2_convert: Error converting bitmaps.\n"));
exit(-1);
}
+
+ for (x = 0; x < rgd->ri.ri_length; x++)
+ rgd->bits[x].bi_bh = bget(sdp, rgd->ri.ri_addr + x);
+
convert_bitmaps(sdp, rgd);
for (x = 0; x < rgd->ri.ri_length; x++) {
if (x)
- gfs2_meta_header_out_bh(&mh, rgd->bh[x]);
+ gfs2_meta_header_out_bh(&mh, rgd->bits[x].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[x]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[x].bi_bh);
}
} /* for each journal */
return error;
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index a72a044..5b824a4 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -259,14 +259,14 @@ static int print_ld_blks(const uint64_t *b, const char *end, int start_line,
sizeof(struct gfs2_meta_header))
* GFS2_NBBY;
bmap = o / sbd.sd_blocks_per_bitmap;
- save_bh = rgd->bh[bmap];
+ save_bh = rgd->bits[bmap].bi_bh;
j_bmap_bh = bread(&sbd, abs_block +
bcount);
- rgd->bh[bmap] = j_bmap_bh;
+ rgd->bits[bmap].bi_bh = j_bmap_bh;
type = lgfs2_get_bitmap(&sbd, tblk,
rgd);
brelse(j_bmap_bh);
- rgd->bh[bmap] = save_bh;
+ rgd->bits[bmap].bi_bh = save_bh;
print_gfs2("bit for blk 0x%llx is %d "
"(%s)",
(unsigned long long)tblk,
diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index a052487..bc4210d 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -652,7 +652,7 @@ int replay_journals(struct gfs2_sbd *sdp, int preen, int force_check,
* don't segfault. */
rgd.start = sdp->sb_addr + 1;
rgd.length = 1;
- rgd.bh = NULL;
+ bits.bi_bh = NULL;
bits.bi_start = 0;
bits.bi_len = sdp->fssize / GFS2_NBBY;
rgd.bits = &bits;
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index f7ea45f..02ecd3f 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -222,7 +222,7 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,
for (x = 0; x < bytes_to_check; x++) {
unsigned char *byte;
- byte = (unsigned char *)&rgd->bh[rgb]->b_data[off + x];
+ byte = (unsigned char *)&rgd->bits[rgb].bi_bh->b_data[off + x];
if (*byte == 0x55) {
diblock += GFS2_NBBY;
continue;
@@ -277,7 +277,7 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,
}
*byte &= ~(GFS2_BIT_MASK <<
(GFS2_BIT_SIZE * y));
- bmodified(rgd->bh[rgb]);
+ bmodified(rgd->bits[rgb].bi_bh);
rg_reclaimed++;
rg_free++;
rgd->rg.rg_free++;
@@ -314,9 +314,9 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,
will be reported. */
if (rg_reclaimed && *fixit) {
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
*this_rg_cleaned = 1;
log_info( _("The rgrp at %lld (0x%llx) was cleaned of %d "
"free metadata blocks.\n"),
@@ -335,10 +335,9 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,
if (query( _("Fix the rgrp free blocks count? (y/n)"))) {
rgd->rg.rg_free = rg_free;
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg,
- rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
*this_rg_fixed = 1;
log_err( _("The rgrp was fixed.\n"));
} else
@@ -354,7 +353,7 @@ static void check_rgrp_integrity(struct gfs2_sbd *sdp, struct rgrp_tree *rgd,
gfs1rg->rg_freemeta, rg_unlinked);
if (query( _("Fix the rgrp free meta blocks count? (y/n)"))) {
gfs1rg->rg_freemeta = rg_unlinked;
- gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
*this_rg_fixed = 1;
log_err( _("The rgrp was fixed.\n"));
} else
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 8da17c6..329fc3b 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -91,17 +91,15 @@ int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk, int error_on_dinode,
}
rgd->rg.rg_free++;
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)
- &rgd->rg, rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
} else if (old_bitmap_state == GFS2_BLKST_FREE) {
rgd->rg.rg_free--;
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)
- &rgd->rg, rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
}
log_err( _("The bitmap was fixed.\n"));
} else {
diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c
index 68b1373..b2e8adf 100644
--- a/gfs2/fsck/pass5.c
+++ b/gfs2/fsck/pass5.c
@@ -218,9 +218,8 @@ static void update_rgrp(struct gfs2_sbd *sdp, struct rgrp_tree *rgp,
bits = &rgp->bits[i];
/* update the bitmaps */
- if (check_block_status(sdp, rgp->bh[i]->b_data +
- bits->bi_offset, bits->bi_len,
- &rg_block, rgp->ri.ri_data0, count))
+ if (check_block_status(sdp, bits->bi_bh->b_data + bits->bi_offset,
+ bits->bi_len, &rg_block, rgp->ri.ri_data0, count))
return;
if (skip_this_pass || fsck_abort) /* if asked to skip the rest */
return;
@@ -275,9 +274,9 @@ static void update_rgrp(struct gfs2_sbd *sdp, struct rgrp_tree *rgp,
log_warn( _("Resource group counts updated\n"));
/* write out the rgrp */
if (sdp->gfs1)
- gfs_rgrp_out(gfs1rg, rgp->bh[0]);
+ gfs_rgrp_out(gfs1rg, rgp->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgp->rg, rgp->bh[0]);
+ gfs2_rgrp_out_bh(&rgp->rg, rgp->bits[0].bi_bh);
} else
log_err( _("Resource group counts left inconsistent\n"));
}
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 0466dd8..dd197d6 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -658,14 +658,14 @@ static int rewrite_rg_block(struct gfs2_sbd *sdp, struct rgrp_tree *rg,
(int)x+1, (int)rg->ri.ri_length, typedesc);
if (query( _("Fix the Resource Group? (y/n)"))) {
log_err( _("Attempting to repair the rgrp.\n"));
- rg->bh[x] = bread(sdp, rg->ri.ri_addr + x);
+ rg->bits[x].bi_bh = bread(sdp, rg->ri.ri_addr + x);
if (x) {
struct gfs2_meta_header mh;
mh.mh_magic = GFS2_MAGIC;
mh.mh_type = GFS2_METATYPE_RB;
mh.mh_format = GFS2_FORMAT_RB;
- gfs2_meta_header_out_bh(&mh, rg->bh[x]);
+ gfs2_meta_header_out_bh(&mh, rg->bits[x].bi_bh);
} else {
if (sdp->gfs1)
memset(&rg->rg, 0, sizeof(struct gfs_rgrp));
@@ -676,13 +676,12 @@ static int rewrite_rg_block(struct gfs2_sbd *sdp, struct rgrp_tree *rg,
rg->rg.rg_header.mh_format = GFS2_FORMAT_RG;
rg->rg.rg_free = rg->ri.ri_data;
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)&rg->rg,
- rg->bh[x]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rg->rg, rg->bits[x].bi_bh);
else
- gfs2_rgrp_out_bh(&rg->rg, rg->bh[x]);
+ gfs2_rgrp_out_bh(&rg->rg, rg->bits[x].bi_bh);
}
- brelse(rg->bh[x]);
- rg->bh[x] = NULL;
+ brelse(rg->bits[x].bi_bh);
+ rg->bits[x].bi_bh = NULL;
return 0;
}
return 1;
@@ -712,7 +711,6 @@ static int expect_rindex_sanity(struct gfs2_sbd *sdp, int *num_rgs)
memcpy(&exp->ri, &rgd->ri, sizeof(exp->ri));
memcpy(&exp->rg, &rgd->rg, sizeof(exp->rg));
exp->bits = NULL;
- exp->bh = NULL;
gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, exp);
}
sdp->rgrps = *num_rgs;
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index 8b439a9..a0f6009 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -680,7 +680,7 @@ uint64_t find_free_blk(struct gfs2_sbd *sdp)
rg = &rl->rg;
for (block = 0; block < ri->ri_length; block++) {
- bh = rl->bh[block];
+ bh = rl->bits[block].bi_bh;
x = (block) ? sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_rgrp);
for (; x < sdp->bsize; x++)
diff --git a/gfs2/libgfs2/fs_bits.c b/gfs2/libgfs2/fs_bits.c
index 7194949..93ddc13 100644
--- a/gfs2/libgfs2/fs_bits.c
+++ b/gfs2/libgfs2/fs_bits.c
@@ -148,7 +148,7 @@ int gfs2_set_bitmap(lgfs2_rgrp_t rgd, uint64_t blkno, int state)
if (bits == NULL)
return -1;
- byte = (unsigned char *)(rgd->bh[buf]->b_data + bits->bi_offset) +
+ byte = (unsigned char *)(bits->bi_bh->b_data + bits->bi_offset) +
(rgrp_block/GFS2_NBBY - bits->bi_start);
bit = (rgrp_block % GFS2_NBBY) * GFS2_BIT_SIZE;
@@ -156,7 +156,7 @@ int gfs2_set_bitmap(lgfs2_rgrp_t rgd, uint64_t blkno, int state)
*byte ^= cur_state << bit;
*byte |= state << bit;
- bmodified(rgd->bh[buf]);
+ bmodified(bits->bi_bh);
return 0;
}
@@ -181,6 +181,7 @@ int lgfs2_get_bitmap(struct gfs2_sbd *sdp, uint64_t blkno, struct rgrp_tree *rgd
uint32_t i = 0;
char *byte;
unsigned int bit;
+ struct gfs2_bitmap *bi;
if (rgd == NULL) {
rgd = gfs2_blk2rgrpd(sdp, blkno);
@@ -205,10 +206,11 @@ int lgfs2_get_bitmap(struct gfs2_sbd *sdp, uint64_t blkno, struct rgrp_tree *rgd
offset -= i * sdp->sd_blocks_per_bitmap;
}
- if (!rgd->bh || !rgd->bh[i])
+ bi = &rgd->bits[i];
+ if (!bi->bi_bh)
return GFS2_BLKST_FREE;
- byte = (rgd->bh[i]->b_data + rgd->bits[i].bi_offset) + (offset/GFS2_NBBY);
+ byte = (bi->bi_bh->b_data + bi->bi_offset) + (offset/GFS2_NBBY);
bit = (offset % GFS2_NBBY) * GFS2_BIT_SIZE;
return (*byte >> bit) & GFS2_BIT_MASK;
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index 587ceb8..c378dba 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -213,11 +213,11 @@ int build_rgrps(struct gfs2_sbd *sdp, int do_write)
if (do_write) {
for (x = 0; x < bitblocks; x++) {
- rl->bh[x] = bget(sdp, rl->start + x);
+ rl->bits[x].bi_bh = bget(sdp, rl->start + x);
if (x)
- gfs2_meta_header_out_bh(&mh, rl->bh[x]);
+ gfs2_meta_header_out_bh(&mh, rl->bits[x].bi_bh);
else
- gfs2_rgrp_out_bh(&rl->rg, rl->bh[x]);
+ gfs2_rgrp_out_bh(&rl->rg, rl->bits[x].bi_bh);
}
}
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 015b974..aa95aa8 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -126,7 +126,7 @@ static uint64_t find_free_block(struct rgrp_tree *rgd)
unsigned long blk = 0;
struct gfs2_bitmap *bits = &rgd->bits[bm];
- blk = gfs2_bitfit((unsigned char *)rgd->bh[bm]->b_data + bits->bi_offset,
+ blk = gfs2_bitfit((uint8_t *)bits->bi_bh->b_data + bits->bi_offset,
bits->bi_len, blk, GFS2_BLKST_FREE);
if (blk != BFITNOENT) {
blkno = blk + (bits->bi_start * GFS2_NBBY) + rgd->ri.ri_data0;
@@ -149,9 +149,9 @@ static int blk_alloc_in_rg(struct gfs2_sbd *sdp, unsigned state, struct rgrp_tre
rgd->rg.rg_free--;
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
sdp->blks_alloced++;
return 0;
@@ -178,7 +178,7 @@ static int block_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, int state,
if (rgt == NULL)
return -1;
- if (rgt->bh[0] == NULL) {
+ if (rgt->bits[0].bi_bh == NULL) {
if (gfs2_rgrp_read(sdp, rgt))
return -1;
release = 1;
@@ -1767,9 +1767,9 @@ void gfs2_free_block(struct gfs2_sbd *sdp, uint64_t block)
gfs2_set_bitmap(rgd, block, GFS2_BLKST_FREE);
rgd->rg.rg_free++; /* adjust the free count */
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
sdp->blks_alloced--;
}
}
@@ -1836,9 +1836,9 @@ int gfs2_freedi(struct gfs2_sbd *sdp, uint64_t diblock)
rgd->rg.rg_free++;
rgd->rg.rg_dinodes--;
if (sdp->gfs1)
- gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bh[0]);
+ gfs_rgrp_out((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_out_bh(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_out_bh(&rgd->rg, rgd->bits[0].bi_bh);
sdp->dinodes_alloced--;
return 0;
}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 2ba97d6..71da81e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -170,6 +170,7 @@ struct device {
struct gfs2_bitmap
{
+ struct gfs2_buffer_head *bi_bh;
uint32_t bi_offset; /* The offset in the buffer of the first byte */
uint32_t bi_start; /* The position of the first byte in this block */
uint32_t bi_len; /* The number of bytes in this block */
@@ -185,7 +186,6 @@ struct rgrp_tree {
struct gfs2_rindex ri;
struct gfs2_rgrp rg;
struct gfs2_bitmap *bits;
- struct gfs2_buffer_head **bh;
};
typedef struct rgrp_tree *lgfs2_rgrp_t;
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index c529594..e929846 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -67,11 +67,6 @@ int gfs2_compute_bitstructs(const uint32_t bsize, struct rgrp_tree *rgd)
rgd->bits[length - 1].bi_len) * GFS2_NBBY != rgd->ri.ri_data)
goto errbits;
- if (rgd->bh == NULL) {
- rgd->bh = calloc(length, sizeof(struct gfs2_buffer_head *));
- if (rgd->bh == NULL)
- goto errbits;
- }
return 0;
errbits:
if (ownbits)
@@ -108,8 +103,9 @@ struct rgrp_tree *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk)
*/
uint64_t gfs2_rgrp_read(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
{
- int x, length = rgd->ri.ri_length;
+ unsigned x, length = rgd->ri.ri_length;
uint64_t max_rgrp_bitbytes, max_rgrp_len;
+ struct gfs2_buffer_head **bhs;
/* Max size of an rgrp is 2GB. Figure out how many blocks that is: */
max_rgrp_bitbytes = ((2147483648 / sdp->bsize) / GFS2_NBBY);
@@ -118,27 +114,38 @@ uint64_t gfs2_rgrp_read(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
return -1;
if (gfs2_check_range(sdp, rgd->ri.ri_addr))
return -1;
- if (breadm(sdp, rgd->bh, length, rgd->ri.ri_addr))
+
+ bhs = calloc(length, sizeof(struct gfs2_buffer_head *));
+ if (bhs == NULL)
+ return -1;
+
+ if (breadm(sdp, bhs, length, rgd->ri.ri_addr)) {
+ free(bhs);
return -1;
- for (x = 0; x < length; x++){
- if(gfs2_check_meta(rgd->bh[x], (x) ? GFS2_METATYPE_RB : GFS2_METATYPE_RG))
- {
- uint64_t error;
+ }
+
+ for (x = 0; x < length; x++) {
+ struct gfs2_bitmap *bi = &rgd->bits[x];
+ int mtype = (x ? GFS2_METATYPE_RB : GFS2_METATYPE_RG);
- error = rgd->ri.ri_addr + x;
+ bi->bi_bh = bhs[x];
+ if (gfs2_check_meta(bi->bi_bh, mtype)) {
+ unsigned err = x;
for (; x >= 0; x--) {
- brelse(rgd->bh[x]);
- rgd->bh[x] = NULL;
+ brelse(rgd->bits[x].bi_bh);
+ rgd->bits[x].bi_bh = NULL;
}
- return error;
+ free(bhs);
+ return rgd->ri.ri_addr + err;
}
}
- if (rgd->bh && rgd->bh[0]) {
+ if (x > 0) {
if (sdp->gfs1)
- gfs_rgrp_in((struct gfs_rgrp *)&rgd->rg, rgd->bh[0]);
+ gfs_rgrp_in((struct gfs_rgrp *)&rgd->rg, rgd->bits[0].bi_bh);
else
- gfs2_rgrp_in(&rgd->rg, rgd->bh[0]);
+ gfs2_rgrp_in(&rgd->rg, rgd->bits[0].bi_bh);
}
+ free(bhs);
return 0;
}
@@ -147,10 +154,9 @@ void gfs2_rgrp_relse(struct rgrp_tree *rgd)
int x, length = rgd->ri.ri_length;
for (x = 0; x < length; x++) {
- if (rgd->bh) {
- if (rgd->bh[x])
- brelse(rgd->bh[x]);
- rgd->bh[x] = NULL;
+ if (rgd->bits[x].bi_bh) {
+ brelse(rgd->bits[x].bi_bh);
+ rgd->bits[x].bi_bh = NULL;
}
}
}
@@ -193,11 +199,12 @@ void gfs2_rgrp_free(struct osi_root *rgrp_tree)
while ((n = osi_first(rgrp_tree))) {
rgd = (struct rgrp_tree *)n;
- if (rgd->bh && rgd->bh[0]) { /* if a buffer exists */
+
+ if (rgd->bits[0].bi_bh) { /* if a buffer exists */
rgs_since_sync++;
if (rgs_since_sync >= RG_SYNC_TOLERANCE) {
if (!sdp)
- sdp = rgd->bh[0]->sdp;
+ sdp = rgd->bits[0].bi_bh->sdp;
fsync(sdp->device_fd);
rgs_since_sync = 0;
}
@@ -205,10 +212,6 @@ void gfs2_rgrp_free(struct osi_root *rgrp_tree)
}
if(rgd->bits)
free(rgd->bits);
- if(rgd->bh) {
- free(rgd->bh);
- rgd->bh = NULL;
- }
osi_erase(&rgd->node, rgrp_tree);
free(rgd);
}
@@ -407,9 +410,9 @@ void lgfs2_rgrps_free(lgfs2_rgrps_t *rgs)
while ((rg = (struct rgrp_tree *)osi_first(tree))) {
int i;
for (i = 0; i < rg->ri.ri_length; i++) {
- if (rg->bh[i] != NULL) {
- free(rg->bh[i]);
- rg->bh[i] = NULL;
+ if (rg->bits[i].bi_bh != NULL) {
+ free(rg->bits[i].bi_bh);
+ rg->bits[i].bi_bh = NULL;
}
}
osi_erase(&rg->node, tree);
@@ -521,14 +524,11 @@ lgfs2_rgrp_t lgfs2_rgrps_append(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry)
link = &lastrg->node.osi_right;
}
- rg = calloc(1, sizeof(*rg) +
- (entry->ri_length * sizeof(struct gfs2_bitmap)) +
- (entry->ri_length * sizeof(struct gfs2_buffer_head *)));
+ rg = calloc(1, sizeof(*rg) + (entry->ri_length * sizeof(struct gfs2_bitmap)));
if (rg == NULL)
return NULL;
rg->bits = (struct gfs2_bitmap *)(rg + 1);
- rg->bh = (struct gfs2_buffer_head **)(rg->bits + entry->ri_length);
osi_link_node(&rg->node, parent, link);
osi_insert_color(&rg->node, &rgs->root);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index ee49dce..9d90657 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -560,7 +560,7 @@ unsigned lgfs2_bm_scan(struct rgrp_tree *rgd, unsigned idx, uint64_t *buf, uint8
uint32_t blk = 0;
while(blk < (bi->bi_len * GFS2_NBBY)) {
- blk = gfs2_bitfit((const unsigned char *)rgd->bh[idx]->b_data + bi->bi_offset,
+ blk = gfs2_bitfit((uint8_t *)bi->bi_bh->b_data + bi->bi_offset,
bi->bi_len, blk, state);
if (blk == BFITNOENT)
break;
9 years, 8 months
gfs2-utils: master - libgfs2: Keep a pointer to the sbd in lgfs2_rgrps_t
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=a5fb90e9...
Commit: a5fb90e9012bda93be4c5a53f3e8fe0cf2922a9a
Parent: 1969548ae01ee6d848e45e684a5ad90f85e94e99
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Apr 4 02:10:17 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Sun Aug 31 23:36:12 2014 +0100
libgfs2: Keep a pointer to the sbd in lgfs2_rgrps_t
As a set of resource groups is tied to a particular file system (block
size, device length...) it makes sense to keep a reference to the file
system in the lgfs2_rgrps_t type. This allows us to avoid duplication of
the bsize and device length fields, reduces parameter counts and
provides a convenient way to access file system-specific values in
resource group-related functions.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/libgfs2.h | 5 +++--
gfs2/libgfs2/rgrp.c | 24 +++++++++++-------------
gfs2/mkfs/main_grow.c | 2 +-
gfs2/mkfs/main_mkfs.c | 2 +-
4 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 041e5fd..2ba97d6 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -175,6 +175,8 @@ struct gfs2_bitmap
uint32_t bi_len; /* The number of bytes in this block */
};
+struct gfs2_sbd;
+
struct rgrp_tree {
struct osi_node node;
uint64_t start; /* The offset of the beginning of this resource group */
@@ -189,7 +191,7 @@ struct rgrp_tree {
typedef struct rgrp_tree *lgfs2_rgrp_t;
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 lgfs2_rgrps_t lgfs2_rgrps_init(const struct gfs2_sbd *sdp, 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);
@@ -223,7 +225,6 @@ struct special_blocks {
uint64_t block;
};
-struct gfs2_sbd;
struct gfs2_inode {
int bh_owned; /* Is this bh owned, iow, should we release it later? */
struct gfs2_dinode i_di;
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index 901a7bf..c529594 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -227,10 +227,9 @@ struct rgplan {
struct _lgfs2_rgrps {
struct osi_root root;
struct rgplan plan[2];
- unsigned bsize;
+ const struct gfs2_sbd *sdp;
unsigned long align;
unsigned long align_off;
- uint64_t devlen;
};
static uint64_t align_block(const uint64_t base, const uint64_t align)
@@ -280,8 +279,8 @@ uint32_t lgfs2_rgrp_align_len(const lgfs2_rgrps_t rgs, uint32_t len)
*/
uint32_t lgfs2_rgrps_plan(const lgfs2_rgrps_t rgs, uint64_t space, uint32_t tgtsize)
{
- uint32_t maxlen = (GFS2_MAX_RGSIZE << 20) / rgs->bsize;
- uint32_t minlen = (GFS2_MIN_RGSIZE << 20) / rgs->bsize;
+ uint32_t maxlen = (GFS2_MAX_RGSIZE << 20) / rgs->sdp->bsize;
+ uint32_t minlen = (GFS2_MIN_RGSIZE << 20) / rgs->sdp->bsize;
/* Apps should already have checked that the rg size is <=
GFS2_MAX_RGSIZE but just in case alignment pushes it over we clamp
@@ -340,7 +339,7 @@ uint32_t lgfs2_rgrps_plan(const lgfs2_rgrps_t rgs, uint64_t space, uint32_t tgts
* offset: The required stripe offset of the resource groups
* Returns an initialised lgfs2_rgrps_t or NULL if unsuccessful with errno set
*/
-lgfs2_rgrps_t lgfs2_rgrps_init(unsigned bsize, uint64_t devlen, uint64_t align, uint64_t offset)
+lgfs2_rgrps_t lgfs2_rgrps_init(const struct gfs2_sbd *sdp, uint64_t align, uint64_t offset)
{
lgfs2_rgrps_t rgs;
@@ -352,8 +351,7 @@ lgfs2_rgrps_t lgfs2_rgrps_init(unsigned bsize, uint64_t devlen, uint64_t align,
if (rgs == NULL)
return NULL;
- rgs->bsize = bsize;
- rgs->devlen = devlen;
+ rgs->sdp = sdp;
rgs->align = align;
rgs->align_off = offset;
memset(&rgs->root, 0, sizeof(rgs->root));
@@ -451,11 +449,11 @@ uint64_t lgfs2_rindex_entry_new(lgfs2_rgrps_t rgs, struct gfs2_rindex *ri, uint6
rgs->plan[plan].num--;
}
- if (addr + len > rgs->devlen)
+ if (addr + len > rgs->sdp->device.length)
return 0;
ri->ri_addr = addr;
- ri->ri_length = rgblocks2bitblocks(rgs->bsize, len, &ri->ri_data);
+ ri->ri_length = rgblocks2bitblocks(rgs->sdp->bsize, len, &ri->ri_data);
ri->__pad = 0;
ri->ri_data0 = ri->ri_addr + ri->ri_length;
ri->ri_bitbytes = ri->ri_data / GFS2_NBBY;
@@ -541,7 +539,7 @@ lgfs2_rgrp_t lgfs2_rgrps_append(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry)
rg->rg.rg_header.mh_format = GFS2_FORMAT_RG;
rg->rg.rg_free = rg->ri.ri_data;
- compute_bitmaps(rg, rgs->bsize);
+ compute_bitmaps(rg, rgs->sdp->bsize);
return rg;
}
@@ -552,7 +550,7 @@ lgfs2_rgrp_t lgfs2_rgrps_append(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry)
int lgfs2_rgrp_write(const lgfs2_rgrps_t rgs, int fd, const lgfs2_rgrp_t rg)
{
ssize_t ret = 0;
- size_t len = rg->ri.ri_length * rgs->bsize;
+ size_t len = rg->ri.ri_length * rgs->sdp->bsize;
unsigned int i;
const struct gfs2_meta_header bmh = {
.mh_magic = GFS2_MAGIC,
@@ -565,9 +563,9 @@ int lgfs2_rgrp_write(const lgfs2_rgrps_t rgs, int fd, const lgfs2_rgrp_t rg)
gfs2_rgrp_out(&rg->rg, buff);
for (i = 1; i < rg->ri.ri_length; i++)
- gfs2_meta_header_out(&bmh, buff + (i * rgs->bsize));
+ gfs2_meta_header_out(&bmh, buff + (i * rgs->sdp->bsize));
- ret = pwrite(fd, buff, len, rg->ri.ri_addr * rgs->bsize);
+ ret = pwrite(fd, buff, len, rg->ri.ri_addr * rgs->sdp->bsize);
if (ret != len) {
free(buff);
return -1;
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 5da809a..95fbd1d 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -178,7 +178,7 @@ static lgfs2_rgrps_t rgrps_init(struct gfs2_sbd *sdp)
}
blkid_free_probe(pr);
- return lgfs2_rgrps_init(sdp->bsize, sdp->device.length, al_base, al_off);
+ return lgfs2_rgrps_init(sdp, al_base, al_off);
}
/**
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index f778e8d..bf7c9cd 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -600,7 +600,7 @@ static lgfs2_rgrps_t rgs_init(struct mkfs_opts *opts, struct gfs2_sbd *sdp)
}
}
- rgs = lgfs2_rgrps_init(sdp->bsize, sdp->device.length, al_base, al_off);
+ rgs = lgfs2_rgrps_init(sdp, al_base, al_off);
if (rgs == NULL) {
perror(_("Could not initialise resource groups"));
exit(-1);
9 years, 8 months
fence-agents: master - fence_ilo_ssh: New fence agent for HP iLO3/4 via SSH
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=5cb174...
Commit: 5cb174f204865d7ffe6d9edbfe8177b54bd61b49
Parent: 6b7ba7c2969169a96146c0f3ed1fa6a0b34ff00f
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Wed Sep 3 14:22:38 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Sep 3 14:22:38 2014 +0200
fence_ilo_ssh: New fence agent for HP iLO3/4 via SSH
Resolves: rhbz#1121122
---
configure.ac | 1 +
fence/agents/ilo_ssh/Makefile.am | 20 +++++++++
fence/agents/ilo_ssh/fence_ilo_ssh.py | 73 +++++++++++++++++++++++++++++++++
3 files changed, 94 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index 0569dfe..b603878 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,7 @@ AC_CONFIG_FILES([Makefile
fence/agents/ilo/Makefile
fence/agents/ilo_moonshot/Makefile
fence/agents/ilo_mp/Makefile
+ fence/agents/ilo_ssh/Makefile
fence/agents/intelmodular/Makefile
fence/agents/ipmilan/Makefile
fence/agents/kdump/Makefile
diff --git a/fence/agents/ilo_ssh/Makefile.am b/fence/agents/ilo_ssh/Makefile.am
new file mode 100644
index 0000000..d67d7d1
--- /dev/null
+++ b/fence/agents/ilo_ssh/Makefile.am
@@ -0,0 +1,20 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+TARGET = fence_ilo_ssh
+
+SRC = $(TARGET).py
+
+EXTRA_DIST = $(SRC)
+
+sbin_SCRIPTS = $(TARGET)
+
+man_MANS = $(TARGET).8
+
+FENCE_TEST_ARGS = -p test -a test
+
+include $(top_srcdir)/make/fencebuild.mk
+include $(top_srcdir)/make/fenceman.mk
+include $(top_srcdir)/make/agentpycheck.mk
+
+clean-local: clean-man
+ rm -f $(TARGET)
diff --git a/fence/agents/ilo_ssh/fence_ilo_ssh.py b/fence/agents/ilo_ssh/fence_ilo_ssh.py
new file mode 100644
index 0000000..f75ac25
--- /dev/null
+++ b/fence/agents/ilo_ssh/fence_ilo_ssh.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python -tt
+
+import sys, re
+import atexit
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION=""
+REDHAT_COPYRIGHT=""
+BUILD_DATE=""
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+ conn.send_eol("show /system1")
+
+ re_state = re.compile('EnabledState=(.*)', re.IGNORECASE)
+ conn.log_expect(options, re_state, int(options["--shell-timeout"]))
+
+ status = conn.match.group(1).lower()
+
+ if status.startswith("enabled"):
+ return "on"
+ else:
+ return "off"
+
+def set_power_status(conn, options):
+ if options["--action"] == "on":
+ conn.send_eol("start /system1")
+ else:
+ conn.send_eol("power off hard")
+
+ conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
+
+ return
+
+def reboot_cycle(conn, options):
+ conn.send_eol("reset hard /system1")
+ conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
+ return
+
+def main():
+ device_opt = ["ipaddr", "login", "passwd", "secure", "cmd_prompt", "method"]
+
+ atexit.register(atexit_handler)
+
+ all_opt["cmd_prompt"]["default"] = ["MP>", "hpiLO->"]
+ all_opt["power_wait"]["default"] = 5
+ all_opt["method"]["default"] = "onoff"
+
+ options = check_input(device_opt, process_input(device_opt))
+
+ docs = {}
+ docs["shortdesc"] = "Fence agent for HP iLO over SSH"
+ docs["longdesc"] = "fence_ilo_ssh is a fence agent that connects to iLO device. It logs into \
+device via ssh and reboot a specified outlet. "
+ docs["vendorurl"] = "http://www.hp.com"
+ docs["symlink"] = [("fence_ilo3_ssh", "Fence agent for HP iLO3 over SSH"),
+ ("fence_ilo4_ssh", "Fence agent for HP iLO4 over SSH")]
+ show_docs(options, docs)
+
+ conn = fence_login(options)
+ conn.send_eol("SMCLP")
+
+ ##
+ ## Fence operations
+ ####
+ result = fence_action(conn, options, set_power_status, get_power_status, None, reboot_cycle)
+ fence_logout(conn, "exit")
+ sys.exit(result)
+
+if __name__ == "__main__":
+ main()
9 years, 8 months
fence-agents: master - [tests] Update XML metadata of fence agents
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=6b7ba7...
Commit: 6b7ba7c2969169a96146c0f3ed1fa6a0b34ff00f
Parent: 809b909651118c06d2ab48d7911bbee2e512e478
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Sep 1 16:37:50 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Sep 1 16:37:50 2014 +0200
[tests] Update XML metadata of fence agents
added --ssl-secure, --ssl-insecure
---
tests/data/metadata/fence_cisco_ucs.xml | 10 ++++++++++
tests/data/metadata/fence_docker.xml | 10 ++++++++++
tests/data/metadata/fence_ilo.xml | 10 ++++++++++
tests/data/metadata/fence_ilo2.xml | 10 ++++++++++
tests/data/metadata/fence_rhevm.xml | 10 ++++++++++
tests/data/metadata/fence_vmware_soap.xml | 10 ++++++++++
6 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/tests/data/metadata/fence_cisco_ucs.xml b/tests/data/metadata/fence_cisco_ucs.xml
index 30a3cb4..75e45ce 100644
--- a/tests/data/metadata/fence_cisco_ucs.xml
+++ b/tests/data/metadata/fence_cisco_ucs.xml
@@ -13,6 +13,11 @@
<content type="boolean" />
<shortdesc lang="en">Disable TLS negotiation</shortdesc>
</parameter>
+ <parameter name="ssl_secure" unique="0" required="0">
+ <getopt mixed="--ssl-secure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection with verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="port" unique="0" required="1">
<getopt mixed="-n, --plug=[id]" />
<content type="string" />
@@ -53,6 +58,11 @@
<content type="string" />
<shortdesc lang="en">Additional path needed to access suborganization</shortdesc>
</parameter>
+ <parameter name="ssl_insecure" unique="0" required="0">
+ <getopt mixed="--ssl-insecure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection without verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="action" unique="0" required="1">
<getopt mixed="-o, --action=[action]" />
<content type="string" default="reboot" />
diff --git a/tests/data/metadata/fence_docker.xml b/tests/data/metadata/fence_docker.xml
index bda31d01..d100b8c 100644
--- a/tests/data/metadata/fence_docker.xml
+++ b/tests/data/metadata/fence_docker.xml
@@ -8,6 +8,11 @@
<content type="string" default="80" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
+ <parameter name="ssl_secure" unique="0" required="0">
+ <getopt mixed="--ssl-secure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection with verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="port" unique="0" required="1">
<getopt mixed="-n, --plug=[id]" />
<content type="string" />
@@ -41,6 +46,11 @@
<content type="boolean" />
<shortdesc lang="en">SSL connection</shortdesc>
</parameter>
+ <parameter name="ssl_insecure" unique="0" required="0">
+ <getopt mixed="--ssl-insecure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection without verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="action" unique="0" required="1">
<getopt mixed="-o, --action=[action]" />
<content type="string" default="reboot" />
diff --git a/tests/data/metadata/fence_ilo.xml b/tests/data/metadata/fence_ilo.xml
index eb8951c..25d9d54 100644
--- a/tests/data/metadata/fence_ilo.xml
+++ b/tests/data/metadata/fence_ilo.xml
@@ -19,6 +19,11 @@
<content type="string" />
<shortdesc lang="en">Force ribcl version to use</shortdesc>
</parameter>
+ <parameter name="ssl_secure" unique="0" required="0">
+ <getopt mixed="--ssl-secure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection with verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="action" unique="0" required="1">
<getopt mixed="-o, --action=[action]" />
<content type="string" default="reboot" />
@@ -54,6 +59,11 @@
<content type="boolean" default="1" />
<shortdesc lang="en">SSL connection</shortdesc>
</parameter>
+ <parameter name="ssl_insecure" unique="0" required="0">
+ <getopt mixed="--ssl-insecure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection without verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="login" unique="0" required="1">
<getopt mixed="-l, --username=[name]" />
<content type="string" />
diff --git a/tests/data/metadata/fence_ilo2.xml b/tests/data/metadata/fence_ilo2.xml
index 4d65808..47e8e28 100644
--- a/tests/data/metadata/fence_ilo2.xml
+++ b/tests/data/metadata/fence_ilo2.xml
@@ -19,6 +19,11 @@
<content type="string" />
<shortdesc lang="en">Force ribcl version to use</shortdesc>
</parameter>
+ <parameter name="ssl_secure" unique="0" required="0">
+ <getopt mixed="--ssl-secure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection with verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="action" unique="0" required="1">
<getopt mixed="-o, --action=[action]" />
<content type="string" default="reboot" />
@@ -54,6 +59,11 @@
<content type="boolean" default="1" />
<shortdesc lang="en">SSL connection</shortdesc>
</parameter>
+ <parameter name="ssl_insecure" unique="0" required="0">
+ <getopt mixed="--ssl-insecure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection without verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="login" unique="0" required="1">
<getopt mixed="-l, --username=[name]" />
<content type="string" />
diff --git a/tests/data/metadata/fence_rhevm.xml b/tests/data/metadata/fence_rhevm.xml
index a47f025..c9d6eeb 100644
--- a/tests/data/metadata/fence_rhevm.xml
+++ b/tests/data/metadata/fence_rhevm.xml
@@ -13,6 +13,11 @@
<content type="boolean" />
<shortdesc lang="en">Disable TLS negotiation</shortdesc>
</parameter>
+ <parameter name="ssl_secure" unique="0" required="0">
+ <getopt mixed="--ssl-secure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection with verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="port" unique="0" required="1">
<getopt mixed="-n, --plug=[id]" />
<content type="string" />
@@ -48,6 +53,11 @@
<content type="boolean" />
<shortdesc lang="en">SSL connection</shortdesc>
</parameter>
+ <parameter name="ssl_insecure" unique="0" required="0">
+ <getopt mixed="--ssl-insecure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection without verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="action" unique="0" required="1">
<getopt mixed="-o, --action=[action]" />
<content type="string" default="reboot" />
diff --git a/tests/data/metadata/fence_vmware_soap.xml b/tests/data/metadata/fence_vmware_soap.xml
index 97d8fc6..d0a465f 100644
--- a/tests/data/metadata/fence_vmware_soap.xml
+++ b/tests/data/metadata/fence_vmware_soap.xml
@@ -15,6 +15,11 @@ Name of virtual machine (-n / port) has to be used in inventory path format (e.g
<content type="boolean" />
<shortdesc lang="en">Disable TLS negotiation</shortdesc>
</parameter>
+ <parameter name="ssl_secure" unique="0" required="0">
+ <getopt mixed="--ssl-secure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection with verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="port" unique="0" required="1">
<getopt mixed="-n, --plug=[id]" />
<content type="string" />
@@ -50,6 +55,11 @@ Name of virtual machine (-n / port) has to be used in inventory path format (e.g
<content type="boolean" />
<shortdesc lang="en">SSL connection</shortdesc>
</parameter>
+ <parameter name="ssl_insecure" unique="0" required="0">
+ <getopt mixed="--ssl-insecure" />
+ <content type="boolean" />
+ <shortdesc lang="en">SSL connection without verifying fence device's certificate</shortdesc>
+ </parameter>
<parameter name="action" unique="0" required="1">
<getopt mixed="-o, --action=[action]" />
<content type="string" default="reboot" />
9 years, 8 months
fence-agents: master - fencing: Add new options --ssl-secure and --ssl-insecure
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=809b90...
Commit: 809b909651118c06d2ab48d7911bbee2e512e478
Parent: 6a0d0f3c2dc3bb91107a4a84b734925af736332a
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Sep 1 15:05:20 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Sep 1 15:05:20 2014 +0200
fencing: Add new options --ssl-secure and --ssl-insecure
These new options extends current --ssl (same as --ssl-secure). Until now certificate of the fence device
was not validated what can possibly lead to attack on infrastructe. With this patch, user can decide
if certificate should (--ssl-secure) or should not (--ssl-insecure) be verified.
The default option is to validate certificate.
Resolves: rhbz#1072564
---
fence/agents/cisco_ucs/fence_cisco_ucs.py | 9 +++++-
fence/agents/lib/fencing.py.py | 28 +++++++++++++++++++--
fence/agents/rhevm/fence_rhevm.py | 9 +++++-
fence/agents/vmware_soap/fence_vmware_soap.py | 33 ++++++++++++++++++++++---
4 files changed, 68 insertions(+), 11 deletions(-)
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index f72e696..888d689 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -90,8 +90,13 @@ def send_command(opt, command, timeout):
conn.setopt(pycurl.POSTFIELDS, command)
conn.setopt(pycurl.WRITEFUNCTION, web_buffer.write)
conn.setopt(pycurl.TIMEOUT, timeout)
- conn.setopt(pycurl.SSL_VERIFYPEER, 0)
- conn.setopt(pycurl.SSL_VERIFYHOST, 0)
+ if opt.has_key("--ssl") or opt.has_key("--ssl-secure"):
+ conn.setopt(pycurl.SSL_VERIFYPEER, 1)
+ conn.setopt(pycurl.SSL_VERIFYHOST, 2)
+
+ if opt.has_key("--ssl-insecure"):
+ conn.setopt(pycurl.SSL_VERIFYPEER, 0)
+ conn.setopt(pycurl.SSL_VERIFYHOST, 0)
conn.perform()
result = web_buffer.getvalue()
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index d1d5aae..557358a 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -179,6 +179,21 @@ all_opt = {
"required" : "0",
"shortdesc" : "SSL connection",
"order" : 1},
+ "ssl_insecure" : {
+ "getopt" : "9",
+ "longopt" : "ssl-insecure",
+ "help" : "--ssl-insecure Use ssl connection without verifying certificate",
+ "required" : "0",
+ "shortdesc" : "SSL connection without verifying fence device's certificate",
+ "order" : 1},
+ "ssl_secure" : {
+ "getopt" : "9",
+ "longopt" : "ssl-secure",
+ "help" : "--ssl-secure Use ssl connection with verifying certificate",
+ "required" : "0",
+ "shortdesc" : "SSL connection with verifying fence device's certificate",
+ "order" : 1},
+
"notls" : {
"getopt" : "t",
"longopt" : "notls",
@@ -385,6 +400,7 @@ DEPENDENCY_OPT = {
"secure" : ["identity_file", "ssh_options"],
"ipaddr" : ["ipport", "inet4_only", "inet6_only"],
"port" : ["separator"],
+ "ssl" : ["ssl_secure", "ssl_insecure"],
"community" : ["snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", \
"snmp_priv_passwd", "snmp_priv_passwd_script"]
}
@@ -662,7 +678,7 @@ def check_input(device_opt, opt):
elif options.has_key("--ssh") or (all_opt["secure"].has_key("default") and all_opt["secure"]["default"] == '1'):
all_opt["ipport"]["default"] = 22
all_opt["ipport"]["help"] = "-u, --ipport=[port] TCP/UDP port to use (default 22)"
- elif options.has_key("--ssl") or (all_opt["ssl"].has_key("default") and all_opt["ssl"]["default"] == '1'):
+ elif options.has_key("--ssl") or options.has_key("--ssl-secure") or options.has_key("--ssl-insecure") or (all_opt["ssl"].has_key("default") and all_opt["ssl"]["default"] == '1'):
all_opt["ipport"]["default"] = 443
all_opt["ipport"]["help"] = "-u, --ipport=[port] TCP/UDP port to use (default 443)"
elif device_opt.count("web"):
@@ -972,11 +988,17 @@ def fence_login(options, re_login_string=r"(login\s*: )|(Login Name: )|(usernam
if options.has_key("--ssl"):
gnutls_opts = ""
+ ssl_opts = ""
+
if options.has_key("--notls"):
gnutls_opts = "--priority \"NORMAL:-VERS-TLS1.2:-VERS-TLS1.1:-VERS-TLS1.0:+VERS-SSL3.0\""
- command = '%s %s --insecure --crlf -p %s %s' % \
- (SSL_PATH, gnutls_opts, options["--ipport"], options["--ip"])
+ # --ssl is same as the --ssl-secure
+ if options.has_key("--ssl-insecure"):
+ ssl_opts = "--insecure"
+
+ command = '%s %s %s --insecure --crlf -p %s %s' % \
+ (SSL_PATH, gnutls_opts, ssl_opts, options["--ipport"], options["--ip"])
try:
conn = fspawn(options, command)
except pexpect.ExceptionPexpect, ex:
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
index a0d8d59..444fb56 100644
--- a/fence/agents/rhevm/fence_rhevm.py
+++ b/fence/agents/rhevm/fence_rhevm.py
@@ -91,8 +91,13 @@ def send_command(opt, command, method="GET"):
conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
conn.setopt(pycurl.USERPWD, opt["--username"] + ":" + opt["--password"])
conn.setopt(pycurl.TIMEOUT, int(opt["--shell-timeout"]))
- conn.setopt(pycurl.SSL_VERIFYPEER, 0)
- conn.setopt(pycurl.SSL_VERIFYHOST, 0)
+ if opt.has_key("--ssl") or opt.has_key("--ssl-secure"):
+ conn.setopt(pycurl.SSL_VERIFYPEER, 1)
+ conn.setopt(pycurl.SSL_VERIFYHOST, 2)
+
+ if opt.has_key("--ssl-insecure"):
+ conn.setopt(pycurl.SSL_VERIFYPEER, 0)
+ conn.setopt(pycurl.SSL_VERIFYHOST, 0)
if method == "POST":
conn.setopt(pycurl.POSTFIELDS, "<action />")
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py
index 53fd9ea..3217c6b 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -2,12 +2,14 @@
import sys
import shutil, tempfile, suds
-import logging
+import logging, requests
import atexit
sys.path.append("@FENCEAGENTSLIBDIR@")
from suds.client import Client
from suds.sudsobject import Property
+from suds.transport.http import HttpAuthenticated
+from suds.transport import Reply, TransportError
from fencing import *
from fencing import fail, EC_STATUS, EC_LOGIN_DENIED, EC_INVALID_PRIVILEGES, EC_WAITING_ON, EC_WAITING_OFF
from fencing import run_delay
@@ -18,12 +20,31 @@ REDHAT_COPYRIGHT=""
BUILD_DATE="April, 2011"
#END_VERSION_GENERATION
+class RequestsTransport(HttpAuthenticated):
+ def __init__(self, **kwargs):
+ self.cert = kwargs.pop('cert', None)
+ self.verify = kwargs.pop('verify', True)
+ self.session = requests.Session()
+ # super won't work because not using new style class
+ HttpAuthenticated.__init__(self, **kwargs)
+
+ def send(self, request):
+ self.addcredentials(request)
+ resp = self.session.post(request.url, data = request.message, headers = request.headers, cert = self.cert, verify = self.verify)
+ result = Reply(resp.status_code, resp.headers, resp.content)
+ return result
+
def soap_login(options):
run_delay(options)
- if options.has_key("--ssl"):
+ if options.has_key("--ssl") or options.has_key("--ssl-secure") or options.has_key("--ssl-insecure"):
+ if options.has_key("--ssl-insecure"):
+ verify = False
+ else:
+ verify = True
url = "https://"
else:
+ verify = False
url = "http://"
url += options["--ip"] + ":" + str(options["--ipport"]) + "/sdk"
@@ -33,8 +54,8 @@ def soap_login(options):
atexit.register(remove_tmp_dir, tmp_dir)
try:
- conn = Client(url + "/vimService.wsdl")
- conn.set_options(location=url)
+ headers = {"Content-Type" : "text/xml;charset=UTF-8", "SOAPAction" : ""}
+ conn = Client(url + "/vimService.wsdl", location = url, transport = RequestsTransport(verify = verify), headers = headers)
mo_ServiceInstance = Property('ServiceInstance')
mo_ServiceInstance._type = 'ServiceInstance'
@@ -43,6 +64,8 @@ def soap_login(options):
mo_SessionManager._type = 'SessionManager'
conn.service.Login(mo_SessionManager, options["--username"], options["--password"])
+ except requests.exceptions.SSLError, ex:
+ fail_usage("Server side certificate verification failed")
except Exception:
fail(EC_LOGIN_DENIED)
@@ -205,6 +228,8 @@ Alternatively you can always use UUID to access virtual machine."
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.CRITICAL)
+ logging.getLogger("requests").setLevel(logging.CRITICAL)
+ logging.getLogger("urllib3").setLevel(logging.CRITICAL)
##
## Operate the fencing device
9 years, 8 months