Пример #1
0
/* temporary for testing */
static int mdc_wr_kuc(struct file *file, const char *buffer,
		      unsigned long count, void *data)
{
	struct obd_device	*obd = data;
	struct kuc_hdr		*lh;
	struct hsm_action_list	*hal;
	struct hsm_action_item	*hai;
	int			 len;
	int			 fd, rc;
	ENTRY;

	rc = lprocfs_write_helper(buffer, count, &fd);
	if (rc)
		RETURN(rc);

	if (fd < 0)
		RETURN(-ERANGE);
	CWARN("message to fd %d\n", fd);

	len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
		/* for mockup below */ 2 * cfs_size_round(sizeof(*hai));

	OBD_ALLOC(lh, len);

	lh->kuc_magic = KUC_MAGIC;
	lh->kuc_transport = KUC_TRANSPORT_HSM;
	lh->kuc_msgtype = HMT_ACTION_LIST;
	lh->kuc_msglen = len;

	hal = (struct hsm_action_list *)(lh + 1);
	hal->hal_version = HAL_VERSION;
	hal->hal_archive_id = 1;
	hal->hal_flags = 0;
	obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN);

	/* mock up an action list */
	hal->hal_count = 2;
	hai = hai_zero(hal);
	hai->hai_action = HSMA_ARCHIVE;
	hai->hai_fid.f_oid = 5;
	hai->hai_len = sizeof(*hai);
	hai = hai_next(hai);
	hai->hai_action = HSMA_RESTORE;
	hai->hai_fid.f_oid = 10;
	hai->hai_len = sizeof(*hai);

	/* This works for either broadcast or unicast to a single fd */
	if (fd == 0) {
		rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
	} else {
		cfs_file_t *fp = cfs_get_fd(fd);
		rc = libcfs_kkuc_msg_put(fp, lh);
		cfs_put_file(fp);
	}
	OBD_FREE(lh, len);
	if (rc < 0)
		RETURN(rc);
	RETURN(count);
}
Пример #2
0
/* temporary for testing */
static ssize_t mdc_kuc_write(struct file *file,
				const char __user *buffer,
				size_t count, loff_t *off)
{
	struct obd_device *obd =
			((struct seq_file *)file->private_data)->private;
	struct kuc_hdr		*lh;
	struct hsm_action_list	*hal;
	struct hsm_action_item	*hai;
	int			 len;
	int			 fd, rc;

	rc = lprocfs_write_helper(buffer, count, &fd);
	if (rc)
		return rc;

	if (fd < 0)
		return -ERANGE;
	CWARN("message to fd %d\n", fd);

	len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
		/* for mockup below */ 2 * cfs_size_round(sizeof(*hai));

	OBD_ALLOC(lh, len);
	if (!lh)
		return -ENOMEM;

	lh->kuc_magic = KUC_MAGIC;
	lh->kuc_transport = KUC_TRANSPORT_HSM;
	lh->kuc_msgtype = HMT_ACTION_LIST;
	lh->kuc_msglen = len;

	hal = (struct hsm_action_list *)(lh + 1);
	hal->hal_version = HAL_VERSION;
	hal->hal_archive_id = 1;
	hal->hal_flags = 0;
	obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN);

	/* mock up an action list */
	hal->hal_count = 2;
	hai = hai_zero(hal);
	hai->hai_action = HSMA_ARCHIVE;
	hai->hai_fid.f_oid = 5;
	hai->hai_len = sizeof(*hai);
	hai = hai_next(hai);
	hai->hai_action = HSMA_RESTORE;
	hai->hai_fid.f_oid = 10;
	hai->hai_len = sizeof(*hai);

	/* This works for either broadcast or unicast to a single fd */
	if (fd == 0) {
		rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
	} else {
		struct file *fp = fget(fd);

		rc = libcfs_kkuc_msg_put(fp, lh);
		fput(fp);
	}
	OBD_FREE(lh, len);
	if (rc < 0)
		return rc;
	return count;
}
Пример #3
0
int main(int argc, char **argv) {
        int c, test = 0;
        struct option long_opts[] = {
                {"test", no_argument, 0, 't'},
                {0, 0, 0, 0}
        };
        int archives[] = {1}; /* which archives we care about */
        int rc;

        optind = 0;
        while ((c = getopt_long(argc, argv, "t", long_opts, NULL)) != -1) {
                switch (c) {
                case 't':
                        test++;
                        break;
                default:
                        fprintf(stderr, "error: %s: option '%s' unrecognized\n",
                                argv[0], argv[optind - 1]);
                        return EINVAL;
                }
        }

        if (optind != argc - 1) {
                fprintf(stderr, "Usage: %s <fsname>\n", argv[0]);
                return -EINVAL;
        }

	rc = llapi_hsm_copytool_start(&ctdata, argv[optind], 0,
                                  ARRAY_SIZE(archives), archives);
        if (rc < 0) {
                fprintf(stderr, "Can't start copytool interface: %s\n",
                        strerror(-rc));
                return -rc;
        }

        if (test)
		return -llapi_hsm_copytool_fini(&ctdata);

        printf("Waiting for message from kernel (pid=%d)\n", getpid());

        signal(SIGINT, handler);

        while(1) {
		struct hsm_action_list *hal;
		struct hsm_action_item *hai;
		int msgsize, i = 0;

		rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
		if (rc == -ESHUTDOWN) {
			fprintf(stderr, "shutting down");
			break;
		}
		if (rc < 0) {
			fprintf(stderr, "Message receive: %s", strerror(-rc));
			break;
		}
		if (msgsize == 0)
			continue; /* msg not for us */

		printf("Copytool fs=%s archive#=%d item_count=%d\n",
			hal->hal_fsname, hal->hal_archive_id, hal->hal_count);

		hai = hai_zero(hal);
		while (++i <= hal->hal_count) {
			printf("Item %d: action %d reclen %d\n", i,
				hai->hai_action, hai->hai_len);
			printf(" "DFID" gid="LPU64" cookie="LPU64"\n",
				PFID(&hai->hai_fid), hai->hai_gid,
				hai->hai_cookie);
			hai = hai_next(hai);
		}

		llapi_hsm_copytool_free(&hal);
        }

	llapi_hsm_copytool_fini(&ctdata);

        return -rc;
}