mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: martin@omnibond.com
To: hubcap@omnibond.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, devel@lists.orangefs.org
Subject: Re: [PATCH 0/7] orangefs uapi
Date: Fri, 26 Jan 2018 14:15:00 -0500	[thread overview]
Message-ID: <20180126191500.GA25950@sassafras.sysblue.org> (raw)
In-Reply-To: <20180126190717.11075-1-martin@omnibond.com>

On Fri, Jan 26, 2018 at 02:07:10PM -0500, Martin Brandenburg wrote:
> I have also written a "fakecore" which does about the bare minimum to
> start up and respond to mount requests.  I intend to use this as a
> vehicle for experimentation with fuzzing and testing performance through
> our kernel code without the rest of OrangeFS running.

#include <sys/ioctl.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "linux/include/uapi/linux/orangefs.h"

#define ORANGEFS_REQDEVICE_NAME          "pvfs2-req"

struct downcall {
	int32_t proto_ver;
	int32_t magic;
	int32_t tag;
	struct orangefs_downcall_s d;
};

struct upcall {
	int32_t proto_ver;
	int32_t magic;
	int32_t tag;
	struct orangefs_upcall_s u;
};

static int mounted = 0;

int process_request(struct upcall *upcall, struct downcall *downcall)
{
	struct stat sb;
	switch (upcall->u.type) {
	case ORANGEFS_VFS_OP_GETATTR:
		downcall->d.resp.getattr.attributes.objtype =
		    ORANGEFS_TYPE_DIRECTORY;
		return 0;
	case ORANGEFS_VFS_OP_FS_MOUNT:
		if (mounted) {
			downcall->d.status = -(ORANGEFS_ERROR_BIT|EPERM);
			return 0;
		}
		downcall->d.resp.fs_mount.fs_id = 1;
		downcall->d.resp.fs_mount.id = mounted;
		downcall->d.resp.fs_mount.root_khandle.u[0] = 1;
		if (stat(".", &sb)) {
			downcall->d.status = -(ORANGEFS_ERROR_BIT|errno);
			return 0;
		}
		memcpy(downcall->d.resp.fs_mount.root_khandle.u, &sb.st_ino,
		    sizeof sb.st_ino);
		mounted = 1;
		return 0;
	case ORANGEFS_VFS_OP_FS_UMOUNT:
		mounted = 0;
		return 0;
	default:
		downcall->d.status = -(ORANGEFS_ERROR_BIT|EPERM);
		return 0;
	}
}

int main(void)
{
	int32_t magic, max_upsize, max_downsize;
	struct downcall downcall;
	struct upcall upcall;
	int fd, upstream;

	fd = open("/dev/" ORANGEFS_REQDEVICE_NAME, O_RDWR|O_NONBLOCK);
	if (fd == -1) {
		perror("open");
		return 1;
	}

	if (ioctl(fd, ORANGEFS_DEV_GET_MAGIC, &magic)) {
		perror("ioctl");
		return 1;
	}
	if (ioctl(fd, ORANGEFS_DEV_GET_MAX_UPSIZE, &max_upsize)) {
		perror("ioctl");
		return 1;
	}
	if (ioctl(fd, ORANGEFS_DEV_GET_MAX_DOWNSIZE, &max_downsize)) {
		perror("ioctl");
		return 1;
	}
	if (ioctl(fd, ORANGEFS_DEV_UPSTREAM, &upstream)) {
		perror("ioctl");
		return 1;
	}

	printf("magic: %d\n", magic);
	printf("max_upsize: %d, sizeof upcall: %d\n",
	    max_upsize, sizeof upcall);
	printf("max_downsize: %d, sizeof downcall: %d\n",
	    max_downsize, sizeof downcall);
	printf("upstream: %d\n", upstream);

	while (1) {
		int r;
		r = read(fd, &upcall, sizeof upcall);
		if (r == -1) {
			if (errno == EAGAIN)
				continue;
			perror("read");
			return 1;
		} else if (r < sizeof upcall) {
			fprintf(stderr, "short read\n");
			return 1;
		}
		downcall.proto_ver = ORANGEFS_MINIMUM_USERSPACE_VERSION;
		downcall.magic = upcall.magic;
		downcall.tag = upcall.tag;
		memset(&downcall.d, 0, sizeof downcall.d);
		downcall.d.type = upcall.u.type;
		downcall.d.status = 0;
		printf("read tag type %d\n", upcall.tag, upcall.u.type);
		if (process_request(&upcall, &downcall)) {
			fprintf(stderr, "process_request failed\n");
			return 1;
		}
		r = write(fd, &downcall, sizeof downcall);
		if (r == -1) {
			perror("write");
			return 1;
		} else if (r < sizeof downcall) {
			perror("short write");
			return 1;
		}
		printf("wrote tag %d status %d\n", downcall.tag,
		    downcall.d.status);
	}

	if (close(fd)) {
		perror("close");
		return 1;
	}
	return 0;
}

      parent reply	other threads:[~2018-01-26 19:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-26 19:07 Martin Brandenburg
2018-01-26 19:07 ` [PATCH 1/7] orangefs: make orangefs_client_debug_init static Martin Brandenburg
2018-01-26 19:07 ` [PATCH 2/7] orangefs: remove gossip_ldebug and gossip_lerr Martin Brandenburg
2018-01-26 19:07 ` [PATCH 3/7] orangefs: remove ORANGEFS_KERNEL_DEBUG Martin Brandenburg
2018-01-26 19:07 ` [PATCH 4/7] orangefs: make orangefs_make_bad_inode static Martin Brandenburg
2018-01-26 19:07 ` [PATCH 5/7] ornagefs: make several *_operations structs static Martin Brandenburg
2018-01-26 19:07 ` [PATCH 6/7] orangefs: remove unused code Martin Brandenburg
2018-01-26 19:07 ` [PATCH 7/7] orangefs: create uapi interface Martin Brandenburg
2018-01-26 19:15 ` martin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180126191500.GA25950@sassafras.sysblue.org \
    --to=martin@omnibond.com \
    --cc=devel@lists.orangefs.org \
    --cc=hubcap@omnibond.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®