Example #1
0
File: libdlm.c Project: beekhof/dlm
static dlm_lshandle_t create_lockspace(const char *name, mode_t mode,
				       uint32_t flags)
{
	char dev_path[PATH_MAX];
	char udev_path[PATH_MAX];
	struct dlm_ls_info *newls;
	int error, saved_errno, minor;

	/* We use the control device for creating lockspaces. */
	if (open_control_device())
		return NULL;

	newls = malloc(sizeof(struct dlm_ls_info));
	if (!newls)
		return NULL;

	ls_dev_name(name, dev_path, sizeof(dev_path));

	if (kernel_version.version[0] == 5)
		minor = create_lockspace_v5(name, flags);
	else
		minor = create_lockspace_v6(name, flags);

	if (minor < 0)
		goto fail;

	/* Wait for udev to create the device; the device it creates may
	   have a truncated name due to the sysfs device name limit. */
	   
	error = find_udev_device(name, minor, udev_path);
	if (error)
		goto fail;

	/* If the symlink already exists, find_udev_device() will return
	   it and we'll skip this. */

	if (strcmp(dev_path, udev_path)) {
		error = symlink(udev_path, dev_path);
		if (error)
			goto fail;
	}

	/* Open it and return the struct as a handle */

	newls->fd = open(dev_path, O_RDWR);
	if (newls->fd == -1)
		goto fail;
	if (mode)
		fchmod(newls->fd, mode);
	newls->tid = 0;
	fcntl(newls->fd, F_SETFD, 1);
	return (dlm_lshandle_t)newls;

 fail:
	saved_errno = errno;
	free(newls);
	errno = saved_errno;
	return NULL;
}
Example #2
0
int setup_misc_devices(void)
{
	int rv;

	find_minors();

	if (control_minor) {
		rv = find_udev_device("/dev/misc/dlm-control", control_minor);
		if (rv < 0)
			return rv;
		log_debug("found /dev/misc/dlm-control minor %u",
			  control_minor);
	}

	if (monitor_minor) {
		rv = find_udev_device("/dev/misc/dlm-monitor", monitor_minor);
		if (rv < 0)
			return rv;
		log_debug("found /dev/misc/dlm-monitor minor %u",
			  monitor_minor);
	}

	if (plock_minor) {
		rv = find_udev_device("/dev/misc/dlm_plock", plock_minor);
		if (rv < 0)
			return rv;
		log_debug("found /dev/misc/dlm_plock minor %u",
			  plock_minor);
	}

	if (!plock_minor && old_plock_minor) {
		rv = find_udev_device("/dev/misc/lock_dlm_plock",
				      old_plock_minor);
		if (rv < 0)
			return rv;
		log_debug("found /dev/misc/lock_dlm_plock minor %u",
			  old_plock_minor);
	}

	return 0;
}