Esempio n. 1
0
/* LINT - not static as fwcadm uses it */
static int
disable_one_sv(char *path)
{
	int setnumber;
	int rc;

	sv_get_maxdevs();
	sv_check_cluster(path);
	sv_cfg_open(CFG_WRLOCK);

	create_cfg_hash();
	if ((setnumber = find_in_hash(path)) != -1) {
		/* remove from kernel */
		if ((rc = disable_dev(path)) == 0) {
			/* remove the cfgline */
			remove_from_cfgfile(path, setnumber);
		} else if (errno == SV_ENODEV) {
			remove_from_cfgfile(path, setnumber);
		}
	} else {
		/* warn the user that we didn't find it in cfg file */
		warn(NULL,
		    gettext("%s was not found in the config storage"), path);
		/* still attempt to remove */
		(void) disable_dev(path);
		rc = 1;
	}
	destroy_hashtable();

	sv_cfg_close();
	return (rc);
}
Esempio n. 2
0
File: node.c Progetto: tonyg/hop
void node_destructor(node_t *n) {
  if (n->node_class->destroy != NULL) {
    n->node_class->destroy(n);
  }
  unbind_all_names_for_node(n);
  destroy_hashtable(&n->names);
  free(n);
}
Esempio n. 3
0
File: devfs.c Progetto: csko/yaosp
__init int init_devfs( void ) {
    int error;

    error = init_hashtable(
        &devfs_node_table, 256,
        devfs_node_key, hash_int64,
        compare_int64
    );

    if ( error < 0 ) {
        goto error1;
    }

    devfs_mutex = mutex_create( "devfs mutex", MUTEX_NONE );

    if ( devfs_mutex < 0 ) {
        error = devfs_mutex;
        goto error2;
    }

    error = register_filesystem( "devfs", &devfs_calls );

    if ( error < 0 ) {
        goto error3;
    }

    return 0;

 error3:
    mutex_destroy( devfs_mutex );

 error2:
    destroy_hashtable( &devfs_node_table );

 error1:
    return error;
}
Esempio n. 4
0
File: node.c Progetto: tonyg/hop
void unbind_all_names_for_node(node_t *n) {
  hashtable_t names = n->names;
  init_node_names(n);
  hashtable_foreach(&names, unbind_on_destroy, NULL);
  destroy_hashtable(&names);
}
Esempio n. 5
0
/* LINT - not static as fwcadm uses it */
static void
print_sv(int verbose)
{
	sv_name_t *svn, *svn_system;	/* Devices in system */
	sv_list_t svl_system;
	int fd, i;
	int setnumber;

	sv_check_cluster(NULL);
	sv_cfg_open(CFG_RDLOCK);

	svn_system = sv_alloc_svnames();

	if ((fd = open(sv_rpath, O_RDONLY)) < 0) {
		(void) printf(gettext("unable to open %s: %s"),
			sv_rpath, strerror(errno));
		return;
	}

	/* Grab the system list from the driver */
	svl_system.svl_count = sv_max_devices;
	svl_system.svl_names = &svn_system[0];
	svl_system.svl_error = spcs_s_ucreate();

	if (ioctl(fd, SVIOC_LIST, &svl_system) < 0) {
		error(&svl_system.svl_error, gettext("unable to get list"));
	}

	spcs_s_ufree(&svl_system.svl_error);
	(void) close(fd);

	/*
	 * We build a hashmap out of the entries from the config file to make
	 * searching faster. We end up taking a performance hit when the # of
	 * volumes is small, but for larger configurations it's a
	 * HUGE improvement.
	 */

	/* build the hashtable */
	cfg_rewind(cfg, CFG_SEC_CONF);
	create_cfg_hash();

	/*
	 * For each volume found from the kernel, print out
	 * info about it from the kernel.
	 */
	for (i = 0; i < svl_system.svl_count; i++) {
		if (*svn_system[i].svn_path == '\0') {
			break;
		}

		svn = &svn_system[i];
		if (svn->svn_mode == 0) {
#ifdef DEBUG
			(void) printf(gettext("%s [kernel guard]\n"),
			    svn->svn_path);
#endif
			continue;
		}
		/* get sv entry from the hashtable */
		if ((setnumber = find_in_hash(svn->svn_path)) != -1) {
			(void) printf("%-*s", STATWIDTH, svn->svn_path);

			if (verbose) {
				print_cluster_tag(setnumber);
			}

			(void) printf("\n");

		} else {
			/*
			 * We didn't find the entry in the hashtable.  Let
			 * the user know that the persistent storage is
			 * inconsistent with the kernel configuration.
			 */
			if (cfg_cluster_tag == NULL)
				warn(NULL, gettext(
					"%s is configured, but not in the "
					"config storage"), svn->svn_path);
		}
	}

	/* free up the hashtable */
	destroy_hashtable();

	sv_cfg_close();
}
Esempio n. 6
0
/* LINT - not static as fwcadm uses it */
static void
compare_sv(char *conf_file)
{
	sv_name_t *svn_config;		/* Devices in config file */
	sv_name_t *svn_system;		/* Devices in system */
	sv_name_t *enable;		/* Devices that need enabled */
	sv_list_t svl_system;
	int config_cnt;
	int sys_cnt = 0;
	int setnumber, i, j;
	int index = 0;	/* Index in enable[] */
	int found;
	int fd0;

	svn_config = sv_alloc_svnames();
	svn_system = sv_alloc_svnames();
	enable = sv_alloc_svnames();

	bzero(svn_system, sizeof (svn_system));
	bzero(&svl_system, sizeof (svl_system));
	bzero(enable, sizeof (enable));

	/*
	 * Read the configuration file
	 * The return value is the number of entries
	 */
	config_cnt = read_config_file(conf_file, svn_config);

	if ((fd0 = open(sv_rpath, O_RDONLY)) < 0)
		error(NULL, gettext("unable to open %s: %s"),
			sv_rpath, strerror(errno));

	/* Grab the system list from the driver */
	svl_system.svl_count = sv_max_devices;
	svl_system.svl_names = &svn_system[0];
	svl_system.svl_error = spcs_s_ucreate();

	if (ioctl(fd0, SVIOC_LIST, &svl_system) < 0) {
		error(&svl_system.svl_error, gettext("unable to get list"));
	}

	spcs_s_ufree(&svl_system.svl_error);
	(void) close(fd0);

	/*
	 * Count the number of devices in the system.
	 * The last entry in the array has '\0' for a path name.
	 */
	for (j = 0; j < sv_max_devices; j++) {
		if (svn_system[j].svn_path[0] != '\0') {
			sys_cnt++;
		} else {
			break;
		}
	}
	/*
	 * Compare the configuration array with the system array.
	 * Mark any differences and disable conflicting devices.
	 */
	for (i = 0; i < config_cnt; i++) {
		found = 0;
		for (j = 0; j < sys_cnt; j++) {
			if (svn_system[j].svn_path[0] == '\0' ||
			    svn_system[j].svn_mode == 0)
				continue;

			/*  Check to see if path matches */
			if (strcmp(svn_system[j].svn_path,
			    svn_config[i].svn_path) == 0) {
				/*  Found a match  */
				svn_system[j].svn_path[0] = '\0';
				found++;
				break;
			}
		}

		if (!found) {
			/* Minor number not in system  = > enable device */
			enable[index].svn_mode = svn_config[i].svn_mode;
			(void) strcpy(enable[index].svn_path,
			    svn_config[i].svn_path);
			index++;
		}
	}

	/* Disable any devices that weren't in the config file */
	for (j = 0; j < sys_cnt; j++) {
		sv_check_cluster(NULL);
		sv_cfg_open(CFG_WRLOCK);
		create_cfg_hash();
		if (svn_system[j].svn_path[0] != '\0' &&
		    svn_system[j].svn_mode != 0) {
			(void) printf(gettext("%s: disabling sv: %s\n"),
			    program, svn_system[j].svn_path);
			if (disable_dev(svn_system[j].svn_path) == 0) {
				setnumber =
					find_in_hash(svn_system[j].svn_path);
				if (setnumber != -1) {
					/* the volume was found in cfg store */
					remove_from_cfgfile(
					svn_system[j].svn_path, setnumber);
				}
			}
		}
		sv_cfg_close();
		destroy_hashtable();
	}

	while (index) {
		/*
		 * Config file doesn't match system => enable the devices
		 * in enable[]
		 */
		index--;
		(void) printf(gettext("%s: enabling new sv: %s\n"),
		    program, enable[index].svn_path);
		(void) enable_dev(&enable[index]);
	}

	/*
	 * Search for entries where the cluster tag has changed.
	 */
	sv_check_cluster(NULL);
	sv_cfg_open(CFG_WRLOCK);

	for (i = 0; i < sv_max_devices; i++) {
		if (svn_config[i].svn_path[0] == '\0')
			break;

		compare_tag(svn_config[i].svn_path);
	}

	sv_cfg_close();
}
Esempio n. 7
0
/* LINT - not static as fwcadm uses it */
static int
disable_sv(char *conf_file)
{
	sv_name_t *svn, *svn_system;	/* Devices in system */
	sv_list_t svl_system;
	int fd, i, setnumber;
	int rc, ret;

	svn_system = sv_alloc_svnames();

	rc = ret = 0;

	if (conf_file == NULL) {
		if ((fd = open(sv_rpath, O_RDONLY)) < 0) {
			(void) printf(gettext("unable to open %s: %s"),
				sv_rpath, strerror(errno));
			return (1);
		}

		/* Grab the system list from the driver */
		svl_system.svl_count = sv_max_devices;
		svl_system.svl_names = &svn_system[0];
		svl_system.svl_error = spcs_s_ucreate();

		if (ioctl(fd, SVIOC_LIST, &svl_system) < 0) {
			error(&(svl_system.svl_error),
					gettext("unable to get list"));
		}

		spcs_s_ufree(&(svl_system.svl_error));
		(void) close(fd);
	} else {
		svl_system.svl_count = read_config_file(conf_file, svn_system);
	}


	for (i = 0; i < svl_system.svl_count; i++) {
		if (*svn_system[i].svn_path == '\0')
			break;

		svn = &svn_system[i];

		sv_check_cluster(svn->svn_path);
		sv_cfg_open(CFG_WRLOCK);
		create_cfg_hash();
		rc = 0;
		if ((setnumber = find_in_hash(svn->svn_path)) != -1) {
			if ((rc = disable_dev(svn->svn_path)) != -1) {
				remove_from_cfgfile(svn->svn_path, setnumber);
			} else if (errno == SV_ENODEV) {
				remove_from_cfgfile(svn->svn_path, setnumber);
			}
		} else {
			/* warn the user that we didn't find it in cfg file */
			warn(NULL, gettext(
				"%s was not found in the config storage"),
				svn->svn_path);
			/* try to disable anyway */
			(void) disable_dev(svn->svn_path);
			rc = 1;
		}

		sv_cfg_close();
		destroy_hashtable();

		if (rc && !ret)
			ret = rc;
	}

	return (ret);
}
Esempio n. 8
0
void done_exchange(void) {
  destroy_hashtable(&all_exchange_types);
}