示例#1
0
文件: fmd.c 项目: andreiw/polaris
void
fmd_door_server(void *dip)
{
	fmd_dprintf(FMD_DBG_XPRT, "door server starting for %p\n", dip);
	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
	(void) door_return(NULL, 0, NULL, 0);
}
示例#2
0
文件: fmd_rpc.c 项目: andreiw/polaris
static int
fmd_rpc_svc_init(void (*disp)(struct svc_req *, SVCXPRT *),
    const char *name, const char *path, const char *prop,
    rpcprog_t pmin, rpcprog_t pmax, rpcvers_t vers,
    uint_t sndsize, uint_t rcvsize, int force)
{
	rpcprog_t prog;
	char buf[16];
	FILE *fp;

	for (prog = pmin; prog <= pmax; prog++) {
		if (fmd_rpc_svc_create_local(disp, prog, vers,
		    sndsize, rcvsize, force) > 0) {
			fmd_dprintf(FMD_DBG_RPC, "registered %s rpc service "
			    "as 0x%lx.%lx\n", name, prog, vers);

			/*
			 * To aid simulator scripts, save our RPC "digits" in
			 * the specified file for rendezvous with libfmd_adm.
			 */
			if (path != NULL && (fp = fopen(path, "w")) != NULL) {
				(void) fprintf(fp, "%ld\n", prog);
				(void) fclose(fp);
			}

			(void) snprintf(buf, sizeof (buf), "%ld", prog);
			(void) fmd_conf_setprop(fmd.d_conf, prop, buf);

			return (0);
		}
	}

	return (-1); /* errno is set for us */
}
示例#3
0
/*
 * Restore a checkpoint for the specified module.  Any errors which occur
 * during restore will call fmd_ckpt_error() or trigger an fmd_api_error(),
 * either of which will automatically unlock the module and trigger an abort.
 */
void
fmd_ckpt_restore(fmd_module_t *mp)
{
	fmd_ckpt_t ckp;

	if (mp->mod_stats->ms_ckpt_restore.fmds_value.b == FMD_B_FALSE)
		return; /* never restore checkpoints for this module */

	TRACE((FMD_DBG_CKPT, "ckpt restore begin %s", mp->mod_name));

	if (fmd_ckpt_open(&ckp, mp) == -1) {
		if (errno != ENOENT)
			fmd_error(EFMD_CKPT_OPEN, "can't open %s", ckp.ckp_src);
		TRACE((FMD_DBG_CKPT, "ckpt restore end %s", mp->mod_name));
		return;
	}

	ASSERT(!fmd_module_locked(mp));
	fmd_ckpt_restore_module(&ckp, mp);
	fmd_ckpt_destroy(&ckp);
	fmd_module_clrdirty(mp);

	TRACE((FMD_DBG_CKPT, "ckpt restore end %s", mp->mod_name));
	fmd_dprintf(FMD_DBG_CKPT, "restored checkpoint of %s\n", mp->mod_name);
}
示例#4
0
void
fmd_ckpt_save(fmd_module_t *mp)
{
	struct stat64 st;
	char path[PATH_MAX];
	mode_t dirmode;

	hrtime_t now = gethrtime();
	fmd_ckpt_t ckp;
	int err;

	ASSERT(fmd_module_locked(mp));

	/*
	 * If checkpointing is disabled for the module, just return.  We must
	 * commit the module state anyway to transition pending log events.
	 */
	if (mp->mod_stats->ms_ckpt_save.fmds_value.b == FMD_B_FALSE) {
		fmd_module_commit(mp);
		return;
	}

	if (!(mp->mod_flags & (FMD_MOD_MDIRTY | FMD_MOD_CDIRTY)))
		return; /* no checkpoint is necessary for this module */

	TRACE((FMD_DBG_CKPT, "ckpt save begin %s %llu",
	    mp->mod_name, mp->mod_gen + 1));

	/*
	 * If the per-module checkpoint directory isn't found or isn't of type
	 * directory, move aside whatever is there (if anything) and attempt
	 * to mkdir(2) a new module checkpoint directory.  If this fails, we
	 * have no choice but to abort the checkpoint and try again later.
	 */
	if (stat64(mp->mod_ckpt, &st) != 0 || !S_ISDIR(st.st_mode)) {
		(void) snprintf(path, sizeof (path), "%s-", mp->mod_ckpt);
		(void) rename(mp->mod_ckpt, path);
		(void) fmd_conf_getprop(fmd.d_conf, "ckpt.dirmode", &dirmode);

		if (mkdir(mp->mod_ckpt, dirmode) != 0) {
			fmd_error(EFMD_CKPT_MKDIR,
			    "failed to mkdir %s", mp->mod_ckpt);
			return; /* return without clearing dirty bits */
		}
	}

	/*
	 * Create a temporary file to write out the checkpoint into, and create
	 * a fmd_ckpt_t structure to manage construction of the checkpoint.  We
	 * then figure out how much space will be required, and allocate it.
	 */
	if (fmd_ckpt_create(&ckp, mp) == -1) {
		fmd_error(EFMD_CKPT_CREATE, "failed to create %s", ckp.ckp_src);
		return;
	}

	fmd_ckpt_resv_module(&ckp, mp);

	if (fmd_ckpt_alloc(&ckp, mp->mod_gen + 1) != 0) {
		fmd_error(EFMD_CKPT_NOMEM, "failed to build %s", ckp.ckp_src);
		fmd_ckpt_destroy(&ckp);
		return;
	}

	/*
	 * Fill in the checkpoint content, write it to disk, sync it, and then
	 * atomically rename it to the destination path.  If this fails, we
	 * have no choice but to leave all our dirty bits set and return.
	 */
	fmd_ckpt_save_module(&ckp, mp);
	err = fmd_ckpt_commit(&ckp);
	fmd_ckpt_destroy(&ckp);

	if (err != 0) {
		fmd_error(EFMD_CKPT_COMMIT, "failed to commit %s", ckp.ckp_dst);
		return; /* return without clearing dirty bits */
	}

	fmd_module_commit(mp);
	TRACE((FMD_DBG_CKPT, "ckpt save end %s", mp->mod_name));

	mp->mod_stats->ms_ckpt_cnt.fmds_value.ui64++;
	mp->mod_stats->ms_ckpt_time.fmds_value.ui64 += gethrtime() - now;

	fmd_dprintf(FMD_DBG_CKPT, "saved checkpoint of %s (%llu)\n",
	    mp->mod_name, mp->mod_gen);
}