コード例 #1
0
ファイル: locking.c プロジェクト: Madabay/lvm2
/*
 * VG locking is by VG name.
 * FIXME This should become VG uuid.
 */
static int _lock_vol(struct cmd_context *cmd, const char *resource,
		     uint32_t flags, lv_operation_t lv_op, struct logical_volume *lv)
{
	uint32_t lck_type = flags & LCK_TYPE_MASK;
	uint32_t lck_scope = flags & LCK_SCOPE_MASK;
	int ret = 0;

	_block_signals(flags);
	_lock_memory(cmd, lv_op);

	assert(resource);

	if (!*resource) {
		log_error(INTERNAL_ERROR "Use of P_orphans is deprecated.");
		return 0;
	}

	if ((is_orphan_vg(resource) || is_global_vg(resource)) && (flags & LCK_CACHE)) {
		log_error(INTERNAL_ERROR "P_%s referenced", resource);
		return 0;
	}

	if (cmd->metadata_read_only && lck_type == LCK_WRITE &&
	    strcmp(resource, VG_GLOBAL)) {
		log_error("Operation prohibited while global/metadata_read_only is set.");
		return 0;
	}

	if ((ret = _locking.lock_resource(cmd, resource, flags, lv))) {
		if (lck_scope == LCK_VG && !(flags & LCK_CACHE)) {
			if (lck_type != LCK_UNLOCK)
				lvmcache_lock_vgname(resource, lck_type == LCK_READ);
			dev_reset_error_count(cmd);
		}

		_update_vg_lock_count(resource, flags);
	} else
		stack;

	/* If unlocking, always remove lock from lvmcache even if operation failed. */
	if (lck_scope == LCK_VG && !(flags & LCK_CACHE) && lck_type == LCK_UNLOCK) {
		lvmcache_unlock_vgname(resource);
		if (!ret)
			_update_vg_lock_count(resource, flags);
	}

	_unlock_memory(cmd, lv_op);
	_unblock_signals();

	return ret;
}
コード例 #2
0
ファイル: zed.c プロジェクト: Spencerx/zfs-1
/*
 * ZFS Event Daemon (ZED).
 */
int
main(int argc, char *argv[])
{
	struct zed_conf *zcp;
	uint64_t saved_eid;
	int64_t saved_etime[2];

	zed_log_init(argv[0]);
	zed_log_stderr_open(LOG_NOTICE);
	zcp = zed_conf_create();
	zed_conf_parse_opts(zcp, argc, argv);
	if (zcp->do_verbose)
		zed_log_stderr_open(LOG_INFO);

	if (geteuid() != 0)
		zed_log_die("Must be run as root");

	(void) umask(0);

	_setup_sig_handlers();

	zed_conf_parse_file(zcp);

	zed_file_close_from(STDERR_FILENO + 1);

	if (chdir("/") < 0)
		zed_log_die("Failed to change to root directory");

	if (zed_conf_scan_dir(zcp) < 0)
		exit(EXIT_FAILURE);

	if (zcp->do_memlock)
		_lock_memory();

	if (!zcp->do_foreground) {
		_become_daemon();
		zed_log_syslog_open(LOG_DAEMON);
		zed_log_stderr_close();
	}
	zed_log_msg(LOG_NOTICE,
	    "ZFS Event Daemon %s-%s", ZFS_META_VERSION, ZFS_META_RELEASE);

	(void) zed_conf_write_pid(zcp);

	if (zed_conf_open_state(zcp) < 0)
		exit(EXIT_FAILURE);

	if (zed_conf_read_state(zcp, &saved_eid, saved_etime) < 0)
		exit(EXIT_FAILURE);

 retry:
	if (zed_event_init(zcp)) {
		/*
		 * If we failed to open /dev/zfs, but force was requested, we
		 * sleep waiting for it to come alive. This lets zed sit around
		 * waiting for the kernel module to load.
		 */
		if (zcp->do_force) {
			sleep(30);
			if (!_got_exit)	goto retry;
		}
		zed_log_die("Failed to initialize libzfs");
    }

	zed_event_seek(zcp, saved_eid, saved_etime);

	while (!_got_exit) {
		if (_got_hup) {
			_got_hup = 0;
			(void) zed_conf_scan_dir(zcp);
		}
		if (zed_event_service(zcp)) break;
	}
	zed_log_msg(LOG_NOTICE, "Exiting");
	zed_event_fini(zcp);
	if (zcp->do_force && !_got_exit) {
		goto retry;
	}
	zed_conf_destroy(zcp);
	zed_log_fini();
	exit(EXIT_SUCCESS);
}
コード例 #3
0
ファイル: irq.c プロジェクト: ChenYingChou/clib
	int _lock_code ( void *_lockaddr, unsigned long _locksize )
	{
		return _lock_memory(_my_cs(),_lockaddr,_locksize) ;
	}
コード例 #4
0
ファイル: zed.c プロジェクト: Acidburn0zzz/zfs
/*
 * ZFS Event Daemon (ZED).
 */
int
main(int argc, char *argv[])
{
	struct zed_conf *zcp;
	uint64_t saved_eid;
	int64_t saved_etime[2];

	zed_log_init(argv[0]);
	zed_log_stderr_open(LOG_NOTICE);
	zcp = zed_conf_create();
	zed_conf_parse_opts(zcp, argc, argv);
	if (zcp->do_verbose)
		zed_log_stderr_open(LOG_INFO);

	if (geteuid() != 0)
		zed_log_die("Must be run as root");

	(void) umask(0);

	_setup_sig_handlers();

	zed_conf_parse_file(zcp);

	zed_file_close_from(STDERR_FILENO + 1);

	if (chdir("/") < 0)
		zed_log_die("Failed to change to root directory");

	if (zed_conf_scan_dir(zcp) < 0)
		exit(EXIT_FAILURE);

	if (zcp->do_memlock)
		_lock_memory();

	if (!zcp->do_foreground) {
		_become_daemon();
		zed_log_syslog_open(LOG_DAEMON);
		zed_log_stderr_close();
	}
	zed_log_msg(LOG_NOTICE,
	    "ZFS Event Daemon %s-%s", ZFS_META_VERSION, ZFS_META_RELEASE);

	(void) zed_conf_write_pid(zcp);

	if (zed_conf_open_state(zcp) < 0)
		exit(EXIT_FAILURE);

	if (zed_conf_read_state(zcp, &saved_eid, saved_etime) < 0)
		exit(EXIT_FAILURE);

	zed_event_init(zcp);
	zed_event_seek(zcp, saved_eid, saved_etime);

	while (!_got_exit) {
		if (_got_hup) {
			_got_hup = 0;
			(void) zed_conf_scan_dir(zcp);
		}
		zed_event_service(zcp);
	}
	zed_log_msg(LOG_NOTICE, "Exiting");
	zed_event_fini(zcp);
	zed_conf_destroy(zcp);
	zed_log_fini();
	exit(EXIT_SUCCESS);
}
コード例 #5
0
ファイル: irq.c プロジェクト: ChenYingChou/clib
	int _lock_data ( void *_lockaddr, unsigned long _locksize )
	{
		return _lock_memory(_my_ds(),_lockaddr,_locksize) ;
	}