Example #1
0
/*
 * steal and convert mherror_t
 */
int
mhstealerror(
	mhd_error_t	*mhep,
	md_error_t	*ep
)
{
	int		rval = -1;

	/* no error */
	if (mhep->errnum == 0) {
		/* assert(mhep->name == NULL); */
		rval = 0;
		goto out;
	}

	/* steal error */
	switch (mhep->errnum) {
	case MHD_E_MAJORITY:
		(void) mderror(ep, MDE_TAKE_OWN, mhep->name);
		break;
	case MHD_E_RESERVED:
		(void) mderror(ep, MDE_RESERVED, mhep->name);
		break;
	default:
		(void) mdsyserror(ep, mhep->errnum, mhep->name);
		break;
	}

	/* cleanup, return success */
out:
	if (mhep->name != NULL)
		Free(mhep->name);
	(void) memset(mhep, 0, sizeof (*mhep));
	return (rval);
}
Example #2
0
void
probe_hotspare_devs(boolean_e verbose)
{
	mdhspnamelist_t *hspnlp = NULL;
	int		cnt;
	mdhspnamelist_t	*p;
	md_hsp_t	*hspp;
	md_error_t	e = mdnullerror;

	if ((cnt = meta_get_hsp_names(sp, &hspnlp, 0, &e)) < 0) {
		mderror(&e, MDE_UNIT_NOT_FOUND, NULL);
		return;
	} else if (cnt == 0) {
		mderror(&e, MDE_NO_HSPS, NULL);
		return;
	}
	for (p = hspnlp; (p != NULL); p = p->next) {
		mdhspname_t	*hspnp = p->hspnamep;

		if (verbose == True)
			monitord_print(6, "%s %s\n", gettext("name"),
			    hspnp->hspname);

		if ((hspp = meta_get_hsp(sp, hspnp, &e)) == NULL)
			continue;

		if (hspp->hotspares.hotspares_len != 0) {
			if (verbose == True)
				monitord_print(6, " %u hotspares\n",
					hspp->hotspares.hotspares_len);
			delete_hotspares_impl(hspnp, hspp, verbose);
		}
	}
	metafreehspnamelist(hspnlp);
}
Example #3
0
/*
 * check to see if current user is root
 */
int
meta_check_root(md_error_t *ep)
{
	if (geteuid() != 0) {
		(void) mderror(ep, MDE_NOPERM, "");
		return (-1);
	}
	return (0);
}
Example #4
0
/*
 * Return the current root filesystem block device name
 */
void *
meta_get_current_root(
    md_error_t	*ep
)
{
    FILE		*fp;
    struct mnttab	mp;

    if ((fp = open_mnttab()) == NULL) {
        (void) mdsyserror(ep, errno, MNTTAB);
        return (NULL);
    }

    while (getmntent(fp, &mp) == 0) {
        if (strcmp(mp.mnt_mountp, "/") == 0)
            return (mp.mnt_special);
    }
    (void) mderror(ep, MDE_NOROOT, NULL);
    return (NULL);
}
Example #5
0
static int
set_hs(
	set_hs_params_t	*shs
)
{
	mdclrerror(&shs->mde);

	if (md_get_setstatus(shs->md_driver.md_setno) & MD_SET_STALE)
		return (mdmddberror(&shs->mde, MDE_DB_STALE, NODEV32,
		    shs->md_driver.md_setno));

	switch (shs->shs_cmd) {
	case ADD_HOT_SPARE:
		return (seths_add(shs));
	case DELETE_HOT_SPARE:
		return (seths_delete(shs));
	case REPLACE_HOT_SPARE:
		return (seths_replace(shs));
	case FIX_HOT_SPARE:
		return (seths_enable(shs));
	default:
		return (mderror(&shs->mde, MDE_INVAL_HSOP));
	}
}
Example #6
0
/*
 * patch filesystem lines into vfstab file, return tempfilename
 */
int
meta_patch_vfstab(
	char		*cmpname,	/* filesystem mount point or */
					/* "swap" if updating swap partition */
	mdname_t	*fsnp,		/* filesystem device name */
	char		*vname,		/* vfstab file name */
	char		*old_bdevname,	/* old name of block device, needed */
					/* for deciding which of multiple   */
					/* swap file entries to change	    */
					/* if NULL then not changing swap   */
	int		doit,		/* really patch file */
	int		verbose,	/* show what we're doing */
	char		**tname,	/* returned temp file name */
	md_error_t	*ep		/* returned error */
)
{
	char		*chrname = fsnp->rname;
	char		*blkname = fsnp->bname;
	FILE		*fp = NULL;
	FILE		*tfp = NULL;
	struct stat	sbuf;
	char		buf[512];
	char		cdev[512];
	char		bdev[512];
	char		mntpt[512];
	char		fstype[512];
	char		fsckpass[512];
	char		mntboot[512];
	char		mntopt[512];
	int		gotfs = 0;
	char		*cmpstr = &mntpt[0]; /* compare against mntpnt if fs, */
						/* or fstype if swap */
	char		*char_device = chrname;

	/* check names */
	assert(vname != NULL);
	assert(tname != NULL);

	/* get temp names */
	*tname = NULL;
	*tname = Malloc(strlen(vname) + strlen(".tmp") + 1);
	(void) strcpy(*tname, vname);
	(void) strcat(*tname, ".tmp");

	/* check if going to update swap entry in file */
	/* if so then compare against file system type */
	if ((old_bdevname != NULL) && (strcmp("swap", cmpname) == 0)) {
	    cmpstr = &fstype[0];
	    char_device = &cdev[0];
	}

	/* copy vfstab file, replace filesystem line */
	if ((fp = fopen(vname, "r")) == NULL) {
		(void) mdsyserror(ep, errno, vname);
		goto out;
	}
	if (fstat(fileno(fp), &sbuf) != 0) {
		(void) mdsyserror(ep, errno, vname);
		goto out;
	}
	if (doit) {
		if ((tfp = fopen(*tname, "w")) == NULL) {
			(void) mdsyserror(ep, errno, *tname);
			goto out;
		}
		if (fchmod(fileno(tfp), (sbuf.st_mode & 0777)) != 0) {
			(void) mdsyserror(ep, errno, *tname);
			goto out;
		}
		if (fchown(fileno(tfp), sbuf.st_uid, sbuf.st_gid) != 0) {
			(void) mdsyserror(ep, errno, *tname);
			goto out;
		}
	}
	while (fgets(buf, sizeof (buf), fp) != NULL) {

	    /* check that have all required params from vfstab file  */
	    /* or that the line isnt a comment	*/
	    /* or that the fstype/mntpoint match what was passed in  */
	    /* or that the block device matches if changing swap */
	    /* the last check is needed since there may be multiple  */
	    /* entries of swap in the file, and so the fstype is not */
	    /* a sufficient check */
		if ((sscanf(buf, "%512s %512s %512s %512s %512s %512s %512s",
		    bdev, cdev, mntpt, fstype, fsckpass,
		    mntboot, mntopt) != 7) ||
		    (bdev[0] == '#') || (strcmp(cmpstr, cmpname) != 0) ||
		    ((old_bdevname != NULL) &&
		    (strstr(bdev, old_bdevname) == NULL))) {
			if (doit) {
			    if (fputs(buf, tfp) == EOF) {
				(void) mdsyserror(ep, errno, *tname);
				goto out;
			    }
			}
			continue;
		}

		if (verbose) {
			(void) printf(dgettext(TEXT_DOMAIN,
			    "Delete the following line from %s:\n\n"),
			    vname);
			(void) printf("%s\n", buf);
			(void) printf(
			    dgettext(TEXT_DOMAIN,
			    "Add the following line to %s:\n\n"),
			    vname);
			(void) printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n\n",
				blkname, char_device, mntpt, fstype, fsckpass,
				mntboot, mntopt);
		}
		if (doit) {
		    if (fprintf(tfp, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
			blkname, char_device, mntpt, fstype, fsckpass,
			mntboot, mntopt) == EOF) {
			(void) mdsyserror(ep, errno, *tname);
			goto out;
		    }
		}


		gotfs = 1;
	}
	if (! feof(fp)) {
		(void) mdsyserror(ep, errno, vname);
		goto out;
	}
	if (! gotfs) {
		(void) mderror(ep, MDE_VFSTAB_FILE, vname);
		goto out;
	}
	if (fclose(fp) != 0) {
		(void) mdsyserror(ep, errno, vname);
		goto out;
	}
	fp = NULL;
	if (doit) {
		if ((fflush(tfp) != 0) ||
		    (fsync(fileno(tfp)) != 0) ||
		    (fclose(tfp) != 0)) {
			(void) mdsyserror(ep, errno, *tname);
			goto out;
		}
		tfp = NULL;
	}

	/* return success */
	return (0);

	/* cleanup, return error */
out:
	if (fp != NULL)
		(void) fclose(fp);
	if (tfp != NULL)
		(void) fclose(tfp);
	if (*tname != NULL) {
		(void) unlink(*tname);
		Free(*tname);
	}
	return (-1);
}