예제 #1
0
static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector, int silent)
{
    struct super_block *sb = sdp->sd_vfs;
    struct gfs2_sb *p;
    struct page *page;
    struct bio *bio;

    page = alloc_page(GFP_NOFS);
    if (unlikely(!page))
        return -ENOBUFS;

    ClearPageUptodate(page);
    ClearPageDirty(page);
    lock_page(page);

    bio = bio_alloc(GFP_NOFS, 1);
    bio->bi_sector = sector * (sb->s_blocksize >> 9);
    bio->bi_bdev = sb->s_bdev;
    bio_add_page(bio, page, PAGE_SIZE, 0);

    bio->bi_end_io = end_bio_io_page;
    bio->bi_private = page;
    submit_bio(READ_SYNC | REQ_META, bio);
    wait_on_page_locked(page);
    bio_put(bio);
    if (!PageUptodate(page)) {
        __free_page(page);
        return -EIO;
    }
    p = kmap(page);
    gfs2_sb_in(sdp, p);
    kunmap(page);
    __free_page(page);
    return gfs2_check_sb(sdp, silent);
}
예제 #2
0
파일: util.c 프로젝트: smintz/cluster
int get_sb(char *device, struct gen_sb *sb_out)
{
	int fd;

	fd = open(device, O_RDONLY);
	if (fd < 0)
		die("can't open %s: %s\n", device, strerror(errno));

	if (!strcmp(fsname, "gfs2")) {
		char buf[GFS2_BASIC_BLOCK];
		struct gfs2_sb sb;

		if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) !=
		    GFS2_SB_ADDR * GFS2_BASIC_BLOCK) {
			fprintf(stderr, "bad seek: %s from %s:%d: "
				"superblock\n",
				strerror(errno), __FUNCTION__, __LINE__);
			exit(-1);
		}
		do_read(fd, buf, GFS2_BASIC_BLOCK);
		gfs2_sb_in(&sb, buf);

		if (sb.sb_header.mh_magic != GFS2_MAGIC ||
	    	    sb.sb_header.mh_type != GFS2_METATYPE_SB) {
			die("there isn't a GFS2 filesystem on %s, "
			    "magic=%x type=%x\n", device,
			    sb.sb_header.mh_magic, sb.sb_header.mh_type);
		}

		if (sb.sb_fs_format != GFS2_FORMAT_FS ||
		    sb.sb_multihost_format != GFS2_FORMAT_MULTI) {
			die("there appears to be a GFS, not GFS2, filesystem "
			    "on %s\n", device);
		}

		strncpy(sb_out->lockproto, sb.sb_lockproto, 256);
		strncpy(sb_out->locktable, sb.sb_locktable, 256);

	} else if (!strcmp(fsname, "gfs")) {
		char buf[GFS_BASIC_BLOCK];
		struct gfs_sb sb;

		if (lseek(fd, GFS_SB_ADDR * GFS_BASIC_BLOCK, SEEK_SET) !=
		    GFS_SB_ADDR * GFS_BASIC_BLOCK) {
			fprintf(stderr, "bad seek: %s from %s:%d: "
				"superblock\n",
				strerror(errno), __FUNCTION__, __LINE__);
			exit(-1);
		}
		do_read(fd, buf, GFS2_BASIC_BLOCK);
		gfs_sb_in(&sb, buf);

		if (sb.sb_header.mh_magic != GFS_MAGIC ||
		    sb.sb_header.mh_type != GFS_METATYPE_SB) {
			die("there isn't a GFS filesystem on %s\n", device);
		}

		if (sb.sb_fs_format != GFS_FORMAT_FS ||
		    sb.sb_multihost_format != GFS_FORMAT_MULTI) {
			die("there appears to be a GFS2, not GFS, filesystem "
			    "on %s\n", device);
		}

		strncpy(sb_out->lockproto, sb.sb_lockproto, 256);
		strncpy(sb_out->locktable, sb.sb_locktable, 256);
	}

	close(fd);
	return 0;
}
예제 #3
0
int display_gfs2(struct gfs2_buffer_head *dbh)
{
	struct gfs2_meta_header mh;
	struct gfs2_rgrp rg;
	struct gfs2_leaf lf;
	struct gfs_log_header lh1;
	struct gfs2_log_header lh;
	struct gfs2_log_descriptor ld;
	struct gfs2_quota_change qc;

	uint32_t magic;

	magic = be32_to_cpu(*(uint32_t *)dbh->b_data);

	switch (magic)
	{
	case GFS2_MAGIC:
		gfs2_meta_header_in(&mh, dbh);
		if (mh.mh_type > GFS2_METATYPE_QC)
			print_gfs2("Unknown metadata type");
		else
			print_gfs2("%s:", block_type_str[mh.mh_type]);
		eol(0);

		switch (mh.mh_type)
		{
		case GFS2_METATYPE_SB:
			gfs2_sb_in(&sbd.sd_sb, dbh);
			gfs2_sb_print2(&sbd.sd_sb);
			break;

		case GFS2_METATYPE_RG:
			if (sbd.gfs1) {
				struct gfs_rgrp rg1;

				gfs1_rgrp_in(&rg1, dbh);
				gfs1_rgrp_print(&rg1);
			} else {
				gfs2_rgrp_in(&rg, dbh);
				gfs2_rgrp_print(&rg);
			}
			break;

		case GFS2_METATYPE_RB:
			gfs2_meta_header_print(&mh);
			break;

		case GFS2_METATYPE_DI:
			gfs2_dinode_print(&di);
			break;

		case GFS2_METATYPE_IN:
			gfs2_meta_header_print(&mh);
			break;

		case GFS2_METATYPE_LF:
			gfs2_leaf_in(&lf, dbh);
			gfs2_leaf_print(&lf);
			break;

		case GFS2_METATYPE_JD:
			gfs2_meta_header_print(&mh);
			break;

		case GFS2_METATYPE_LH:
			if (sbd.gfs1) {
				gfs_log_header_in(&lh1, dbh);
				gfs_log_header_print(&lh1);
			} else {
				gfs2_log_header_in(&lh, dbh);
				gfs2_log_header_print(&lh);
			}
			break;

		case GFS2_METATYPE_LD:
			gfs2_log_descriptor_in(&ld, dbh);
			gfs2_log_descriptor_print(&ld);
			break;

		case GFS2_METATYPE_EA:
			do_eattr_extended(dbh);
			break;

		case GFS2_METATYPE_ED:
			gfs2_meta_header_print(&mh);
			break;

		case GFS2_METATYPE_LB:
			gfs2_meta_header_print(&mh);
			break;

		case GFS2_METATYPE_QC:
			gfs2_quota_change_in(&qc, dbh);
			gfs2_quota_change_print(&qc);
			break;

		default:
			break;
		}
		break;

	default:
		print_gfs2("Unknown block type");
		eol(0);
		break;
	};
	return(0);
}