⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 super.c

📁 ocfs1.2.7 源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* -*- mode: c; c-basic-offset: 8; -*- * vim: noexpandtab sw=8 ts=8 sts=0: * * super.c * * load/unload driver, mount/dismount volumes * * Copyright (C) 2002, 2004 Oracle.  All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 021110-1307, USA. */#include <linux/module.h>#include <linux/fs.h>#include <linux/types.h>#include <linux/slab.h>#include <linux/highmem.h>#include <linux/utsname.h>#include <linux/init.h>#include <linux/random.h>#include <linux/statfs.h>#include <linux/moduleparam.h>#include <linux/blkdev.h>#include <linux/socket.h>#include <linux/inet.h>#include <linux/parser.h>#include <linux/crc32.h>#include <linux/debugfs.h>#include <cluster/nodemanager.h>#define MLOG_MASK_PREFIX ML_SUPER#include <cluster/masklog.h>#include "ocfs2.h"#include "aio.h"/* this should be the only file to include a version 1 header */#include "ocfs1_fs_compat.h"#include "alloc.h"#include "dlmglue.h"#include "export.h"#include "extent_map.h"#include "heartbeat.h"#include "inode.h"#include "journal.h"#include "localalloc.h"#include "namei.h"#include "proc.h"#include "slot_map.h"#include "super.h"#include "sysfile.h"#include "uptodate.h"#include "ver.h"#include "vote.h"#include "buffer_head_io.h"/* * Globals */static spinlock_t ocfs2_globals_lock = SPIN_LOCK_UNLOCKED;static u32 osb_id;             /* Keeps track of next available OSB Id */static kmem_cache_t *ocfs2_inode_cachep = NULL;kmem_cache_t *ocfs2_lock_cache = NULL;/* OCFS2 needs to schedule several differnt types of work which * require cluster locking, disk I/O, recovery waits, etc. Since these * types of work tend to be heavy we avoid using the kernel events * workqueue and schedule on our own. */struct workqueue_struct *ocfs2_wq = NULL;static struct dentry *ocfs2_debugfs_root = NULL;MODULE_AUTHOR("Oracle");MODULE_LICENSE("GPL");static int ocfs2_parse_options(struct super_block *sb, char *options,			       unsigned long *mount_opt, s16 *slot,			       int is_remount);static void ocfs2_put_super(struct super_block *sb);static int ocfs2_mount_volume(struct super_block *sb);static int ocfs2_remount(struct super_block *sb, int *flags, char *data);static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);static int ocfs2_initialize_mem_caches(void);static void ocfs2_free_mem_caches(void);static void ocfs2_delete_osb(struct ocfs2_super *osb);#ifdef STATFS_GETS_SBstatic int ocfs2_statfs(struct super_block *sb, struct kstatfs *buf);#elsestatic int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);#endifstatic int ocfs2_sync_fs(struct super_block *sb, int wait);static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);static int ocfs2_release_system_inodes(struct ocfs2_super *osb);static int ocfs2_fill_local_node_info(struct ocfs2_super *osb);static int ocfs2_check_volume(struct ocfs2_super *osb);static int ocfs2_verify_volume(struct ocfs2_dinode *di,			       struct buffer_head *bh,			       u32 sectsize);static int ocfs2_initialize_super(struct super_block *sb,				  struct buffer_head *bh,				  int sector_size);static int ocfs2_get_sector(struct super_block *sb,			    struct buffer_head **bh,			    int block,			    int sect_size);static void ocfs2_write_super(struct super_block *sb);static struct inode *ocfs2_alloc_inode(struct super_block *sb);static void ocfs2_destroy_inode(struct inode *inode);static unsigned long long ocfs2_max_file_offset(unsigned int blockshift);static struct super_operations ocfs2_sops = {	.statfs		= ocfs2_statfs,	.alloc_inode	= ocfs2_alloc_inode,	.destroy_inode	= ocfs2_destroy_inode,	.drop_inode	= ocfs2_drop_inode,	.clear_inode	= ocfs2_clear_inode,	.delete_inode	= ocfs2_delete_inode,	.sync_fs	= ocfs2_sync_fs,	.write_super	= ocfs2_write_super,	.put_super	= ocfs2_put_super,	.remount_fs	= ocfs2_remount,};#ifdef OCFS2_ORACORE_WORKAROUNDS#define OCFS_SUPER_MAGIC		0xa156f7eb#endifenum {	Opt_barrier,	Opt_err_panic,	Opt_err_ro,#ifdef OCFS2_ORACORE_WORKAROUNDS	Opt_datavolume,#endif	Opt_intr,	Opt_nointr,	Opt_hb_none,	Opt_hb_local,	Opt_slot,	Opt_err,};static match_table_t tokens = {	{Opt_barrier, "barrier=%u"},	{Opt_err_panic, "errors=panic"},	{Opt_err_ro, "errors=remount-ro"},#ifdef OCFS2_ORACORE_WORKAROUNDS	{Opt_datavolume, "datavolume"},#endif	{Opt_intr, "intr"},	{Opt_nointr, "nointr"},	{Opt_hb_none, OCFS2_HB_NONE},	{Opt_hb_local, OCFS2_HB_LOCAL},	{Opt_slot, "preferred_slot=%u"},	{Opt_err, NULL}};/* * write_super and sync_fs ripped right out of ext3. */static void ocfs2_write_super(struct super_block *sb){	if (!mutex_trylock(&sb->s_lock) == 0)		BUG();	sb->s_dirt = 0;}static int ocfs2_sync_fs(struct super_block *sb, int wait){	int status = 0;	tid_t target;	struct ocfs2_super *osb = OCFS2_SB(sb);	sb->s_dirt = 0;	if (ocfs2_is_hard_readonly(osb))		return -EROFS;	if (wait) {		status = ocfs2_flush_truncate_log(osb);		if (status < 0)			mlog_errno(status);	} else {		ocfs2_schedule_truncate_log_flush(osb, 0);	}	if (journal_start_commit(OCFS2_SB(sb)->journal->j_journal, &target)) {		if (wait)			log_wait_commit(OCFS2_SB(sb)->journal->j_journal,					target);	}	return 0;}static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb){	struct inode *new = NULL;	int status = 0;	int i;	mlog_entry_void();	new = ocfs2_iget(osb, osb->root_blkno);	if (IS_ERR(new)) {		status = PTR_ERR(new);		mlog_errno(status);		goto bail;	}	osb->root_inode = new;	new = ocfs2_iget(osb, osb->system_dir_blkno);	if (IS_ERR(new)) {		status = PTR_ERR(new);		mlog_errno(status);		goto bail;	}	osb->sys_root_inode = new;	for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;	     i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {		new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);		if (!new) {			ocfs2_release_system_inodes(osb);			status = -EINVAL;			mlog_errno(status);			/* FIXME: Should ERROR_RO_FS */			mlog(ML_ERROR, "Unable to load system inode %d, "			     "possibly corrupt fs?", i);			goto bail;		}		// the array now has one ref, so drop this one		iput(new);	}bail:	mlog_exit(status);	return status;}static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb){	struct inode *new = NULL;	int status = 0;	int i;	mlog_entry_void();	for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;	     i < NUM_SYSTEM_INODES;	     i++) {		new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);		if (!new) {			ocfs2_release_system_inodes(osb);			status = -EINVAL;			mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",			     status, i, osb->slot_num);			goto bail;		}		/* the array now has one ref, so drop this one */		iput(new);	}bail:	mlog_exit(status);	return status;}static int ocfs2_release_system_inodes(struct ocfs2_super *osb){	int status = 0, i;	struct inode *inode;	mlog_entry_void();	for (i = 0; i < NUM_SYSTEM_INODES; i++) {		inode = osb->system_inodes[i];		if (inode) {			iput(inode);			osb->system_inodes[i] = NULL;		}	}	inode = osb->sys_root_inode;	if (inode) {		iput(inode);		osb->sys_root_inode = NULL;	}	inode = osb->root_inode;	if (inode) {		iput(inode);		osb->root_inode = NULL;	}	mlog_exit(status);	return status;}/* We're allocating fs objects, use GFP_NOFS */static struct inode *ocfs2_alloc_inode(struct super_block *sb){	struct ocfs2_inode_info *oi;	oi = kmem_cache_alloc(ocfs2_inode_cachep, SLAB_NOFS);	if (!oi)		return NULL;	return &oi->vfs_inode;}static void ocfs2_destroy_inode(struct inode *inode){	kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));}/* From xfs_super.c:xfs_max_file_offset * Copyright (c) 2000-2004 Silicon Graphics, Inc. */static unsigned long long ocfs2_max_file_offset(unsigned int blockshift){	unsigned int pagefactor = 1;	unsigned int bitshift = BITS_PER_LONG - 1;	/* Figure out maximum filesize, on Linux this can depend on	 * the filesystem blocksize (on 32 bit platforms).	 * __block_prepare_write does this in an [unsigned] long...	 *      page->index << (PAGE_CACHE_SHIFT - bbits)	 * So, for page sized blocks (4K on 32 bit platforms),	 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is	 *      (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)	 * but for smaller blocksizes it is less (bbits = log2 bsize).	 * Note1: get_block_t takes a long (implicit cast from above)	 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch	 * can optionally convert the [unsigned] long from above into	 * an [unsigned] long long.	 */#if BITS_PER_LONG == 32# if defined(CONFIG_LBD)	BUG_ON(sizeof(sector_t) != 8);	pagefactor = PAGE_CACHE_SIZE;	bitshift = BITS_PER_LONG;# else	pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);# endif#endif	return (((unsigned long long)pagefactor) << bitshift) - 1;}static int ocfs2_remount(struct super_block *sb, int *flags, char *data){	int incompat_features;	int ret = 0;	unsigned long parsed_options;	s16 slot;	struct ocfs2_super *osb = OCFS2_SB(sb);	if (!ocfs2_parse_options(sb, data, &parsed_options, &slot, 1)) {		ret = -EINVAL;		goto out;	}	/* We're going to/from readonly mode. */	if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {		/* Lock here so the check of HARD_RO and the potential		 * setting of SOFT_RO is atomic. */		spin_lock(&osb->osb_lock);		if (osb->osb_flags & OCFS2_OSB_HARD_RO) {			mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");			ret = -EROFS;			goto unlock_osb;		}		if (*flags & MS_RDONLY) {			mlog(0, "Going to ro mode.\n");			sb->s_flags |= MS_RDONLY;			osb->osb_flags |= OCFS2_OSB_SOFT_RO;		} else {			mlog(0, "Making ro filesystem writeable.\n");			if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {				mlog(ML_ERROR, "Cannot remount RDWR "				     "filesystem due to previous errors.\n");				ret = -EROFS;				goto unlock_osb;			}			incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);			if (incompat_features) {				mlog(ML_ERROR, "Cannot remount RDWR because "				     "of unsupported optional features "				     "(%x).\n", incompat_features);				ret = -EINVAL;				goto unlock_osb;			}			sb->s_flags &= ~MS_RDONLY;			osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;		}unlock_osb:		spin_unlock(&osb->osb_lock);	}	if (!ret) {		if (!ocfs2_is_hard_readonly(osb))			ocfs2_set_journal_params(osb);		/* Only save off the new mount options in case of a successful		 * remount. */		osb->s_mount_opt = parsed_options;	}out:	return ret;}static int ocfs2_sb_probe(struct super_block *sb,			  struct buffer_head **bh,			  int *sector_size){	int status = 0, tmpstat;	struct ocfs1_vol_disk_hdr *hdr;	struct ocfs2_dinode *di;	int blksize;	*bh = NULL;	/* may be > 512 */	*sector_size = bdev_hardsect_size(sb->s_bdev);	if (*sector_size > OCFS2_MAX_BLOCKSIZE) {		mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",		     *sector_size, OCFS2_MAX_BLOCKSIZE);		status = -EINVAL;		goto bail;	}	/* Can this really happen? */	if (*sector_size < OCFS2_MIN_BLOCKSIZE)		*sector_size = OCFS2_MIN_BLOCKSIZE;	/* check block zero for old format */	status = ocfs2_get_sector(sb, bh, 0, *sector_size);	if (status < 0) {		mlog_errno(status);		goto bail;	}	hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;	if (hdr->major_version == OCFS1_MAJOR_VERSION) {		mlog(ML_ERROR, "incompatible version: %u.%u\n",		     hdr->major_version, hdr->minor_version);		status = -EINVAL;	}	if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,		   strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {		mlog(ML_ERROR, "incompatible volume signature: %8s\n",		     hdr->signature);		status = -EINVAL;	}	brelse(*bh);	*bh = NULL;	if (status < 0) {		mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "		     "upgraded before mounting with ocfs v2\n");		goto bail;	}	/*	 * Now check at magic offset for 512, 1024, 2048, 4096	 * blocksizes.  4096 is the maximum blocksize because it is	 * the minimum clustersize.	 */	status = -EINVAL;	for (blksize = *sector_size;	     blksize <= OCFS2_MAX_BLOCKSIZE;	     blksize <<= 1) {		tmpstat = ocfs2_get_sector(sb, bh,					   OCFS2_SUPER_BLOCK_BLKNO,					   blksize);		if (tmpstat < 0) {			status = tmpstat;			mlog_errno(status);			goto bail;		}		di = (struct ocfs2_dinode *) (*bh)->b_data;		status = ocfs2_verify_volume(di, *bh, blksize);		if (status >= 0)			goto bail;		brelse(*bh);		*bh = NULL;		if (status != -EAGAIN)			break;	}bail:	return status;}static int ocfs2_verify_heartbeat(struct ocfs2_super *osb){	if (ocfs2_mount_local(osb)) {		if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {			mlog(ML_ERROR, "Cannot heartbeat on a locally "			     "mounted device.\n");			return -EINVAL;		}	}	if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {		if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb)) {			mlog(ML_ERROR, "Heartbeat has to be started to mount "			     "a read-write clustered device.\n");			return -EINVAL;		}	}	return 0;}static int ocfs2_fill_super(struct super_block *sb, void *data, int silent){	struct dentry *root;	int status, sector_size;	unsigned long parsed_opt;	s16 slot;	struct inode *inode = NULL;	struct ocfs2_super *osb = NULL;	struct buffer_head *bh = NULL;	char nodestr[8];	mlog_entry("%p, %p, %i", sb, data, silent);	if (!ocfs2_parse_options(sb, data, &parsed_opt, &slot, 0)) {		status = -EINVAL;		goto read_super_error;	}	/* for now we only have one cluster/node, make sure we see it	 * in the heartbeat universe */	if (parsed_opt & OCFS2_MOUNT_HB_LOCAL) {		if (!o2hb_check_local_node_heartbeating()) {			status = -EINVAL;			goto read_super_error;		}	}	/* probe for superblock */	status = ocfs2_sb_probe(sb, &bh, &sector_size);	if (status < 0) {		mlog(ML_ERROR, "superblock probe failed!\n");		goto read_super_error;	}	status = ocfs2_initialize_super(sb, bh, sector_size);	osb = OCFS2_SB(sb);	if (status < 0) {		mlog_errno(status);		goto read_super_error;	}	brelse(bh);	bh = NULL;	osb->s_mount_opt = parsed_opt;	osb->preferred_slot = slot;#ifdef OCFS2_ORACORE_WORKAROUNDS	if (osb->s_mount_opt & OCFS2_MOUNT_COMPAT_OCFS)		sb->s_magic = OCFS_SUPER_MAGIC;	else#endif		sb->s_magic = OCFS2_SUPER_MAGIC;	/* Hard readonly mode only if: bdev_read_only, MS_RDONLY,	 * heartbeat=none */	if (bdev_read_only(sb->s_bdev)) {		if (!(sb->s_flags & MS_RDONLY)) {			status = -EACCES;			mlog(ML_ERROR, "Readonly device detected but readonly "			     "mount was not specified.\n");			goto read_super_error;		}		/* You should not be able to start a local heartbeat		 * on a readonly device. */		if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {			status = -EROFS;			mlog(ML_ERROR, "Local heartbeat specified on readonly "			     "device.\n");			goto read_super_error;		}		status = ocfs2_check_journals_nolocks(osb);		if (status < 0) {			if (status == -EROFS)				mlog(ML_ERROR, "Recovery required on readonly "				     "file system, but write access is "				     "unavailable.\n");			else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -