Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a61f334f authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds
Browse files

uml: convert libc layer to call read and write



This patch converts calls in the os layer to os_{read,write}_file to calls
directly to libc read() and write() where it is clear that the I/O buffer is
in the kernel.

We can do that here instead of calling os_{read,write}_file_k since we are in
libc code and can call libc directly.

With the change in the calls, error handling needs to be changed to refer to
errno directly rather than the return value of the call.

CATCH_EINTR wrappers were also added where needed.

Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ef0470c0
Loading
Loading
Loading
Loading
+20 −16
Original line number Diff line number Diff line
@@ -132,10 +132,10 @@ static int aio_thread(void *arg)
				{ .data = (void *) (long) event.data,
						.err	= event.res });
			reply_fd = ((struct aio_context *) reply.data)->reply_fd;
			err = os_write_file(reply_fd, &reply, sizeof(reply));
			err = write(reply_fd, &reply, sizeof(reply));
			if(err != sizeof(reply))
				printk("aio_thread - write failed, fd = %d, "
				       "err = %d\n", reply_fd, -err);
				       "err = %d\n", reply_fd, errno);
		}
	}
	return 0;
@@ -147,7 +147,7 @@ static int do_not_aio(struct aio_thread_req *req)
{
	char c;
	unsigned long long actual;
	int err;
	int n;

	actual = lseek64(req->io_fd, req->offset, SEEK_SET);
	if(actual != req->offset)
@@ -155,21 +155,22 @@ static int do_not_aio(struct aio_thread_req *req)

	switch(req->type){
	case AIO_READ:
		err = os_read_file(req->io_fd, req->buf, req->len);
		n = read(req->io_fd, req->buf, req->len);
		break;
	case AIO_WRITE:
		err = os_write_file(req->io_fd, req->buf, req->len);
		n = write(req->io_fd, req->buf, req->len);
		break;
	case AIO_MMAP:
		err = os_read_file(req->io_fd, &c, sizeof(c));
		n = read(req->io_fd, &c, sizeof(c));
		break;
	default:
		printk("do_not_aio - bad request type : %d\n", req->type);
		err = -EINVAL;
		break;
		return -EINVAL;
	}

	return err;
	if(n < 0)
		return -errno;
	return 0;
}

/* These are initialized in initcalls and not changed */
@@ -185,12 +186,12 @@ static int not_aio_thread(void *arg)

	signal(SIGWINCH, SIG_IGN);
	while(1){
		err = os_read_file(aio_req_fd_r, &req, sizeof(req));
		err = read(aio_req_fd_r, &req, sizeof(req));
		if(err != sizeof(req)){
			if(err < 0)
				printk("not_aio_thread - read failed, "
				       "fd = %d, err = %d\n", aio_req_fd_r,
				       -err);
				       errno);
			else {
				printk("not_aio_thread - short read, fd = %d, "
				       "length = %d\n", aio_req_fd_r, err);
@@ -200,10 +201,10 @@ static int not_aio_thread(void *arg)
		err = do_not_aio(&req);
		reply = ((struct aio_thread_reply) { .data 	= req.aio,
						     .err	= err });
		err = os_write_file(req.aio->reply_fd, &reply, sizeof(reply));
		err = write(req.aio->reply_fd, &reply, sizeof(reply));
		if(err != sizeof(reply))
			printk("not_aio_thread - write failed, fd = %d, "
			       "err = %d\n", req.aio->reply_fd, -err);
			       "err = %d\n", req.aio->reply_fd, errno);
	}

	return 0;
@@ -277,10 +278,12 @@ static int submit_aio_26(enum aio_type type, int io_fd, char *buf, int len,
	if(err){
		reply = ((struct aio_thread_reply) { .data = aio,
					 .err  = err });
		err = os_write_file(aio->reply_fd, &reply, sizeof(reply));
		if(err != sizeof(reply))
		err = write(aio->reply_fd, &reply, sizeof(reply));
		if(err != sizeof(reply)){
			err = -errno;
			printk("submit_aio_26 - write failed, "
			       "fd = %d, err = %d\n", aio->reply_fd, -err);
		}
		else err = 0;
	}

@@ -375,9 +378,10 @@ static int submit_aio_24(enum aio_type type, int io_fd, char *buf, int len,
	};
	int err;

	err = os_write_file(aio_req_fd_w, &req, sizeof(req));
	err = write(aio_req_fd_w, &req, sizeof(req));
	if(err == sizeof(req))
		err = 0;
	else err = -errno;

	return err;
}
+6 −5
Original line number Diff line number Diff line
@@ -48,9 +48,9 @@ static void etap_change(int op, unsigned char *addr, unsigned char *netmask,
	change.what = op;
	memcpy(change.addr, addr, sizeof(change.addr));
	memcpy(change.netmask, netmask, sizeof(change.netmask));
	n = os_write_file(fd, &change, sizeof(change));
	CATCH_EINTR(n = write(fd, &change, sizeof(change)));
	if(n != sizeof(change)){
		printk("etap_change - request failed, err = %d\n", -n);
		printk("etap_change - request failed, err = %d\n", errno);
		return;
	}

@@ -123,10 +123,11 @@ static int etap_tramp(char *dev, char *gate, int control_me,
		err = pid;
	os_close_file(data_remote);
	os_close_file(control_remote);
	n = os_read_file(control_me, &c, sizeof(c));
	CATCH_EINTR(n = read(control_me, &c, sizeof(c)));
	if(n != sizeof(c)){
		printk("etap_tramp : read of status failed, err = %d\n", -n);
		return -EINVAL;
		err = -errno;
		printk("etap_tramp : read of status failed, err = %d\n", -err);
		return err;
	}
	if(c != 1){
		printk("etap_tramp : uml_net failed\n");
+3 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ static int helper_child(void *arg)
	errval = execvp_noalloc(data->buf, argv[0], argv);
	printk("helper_child - execvp of '%s' failed - errno = %d\n", argv[0],
	       -errval);
	os_write_file(data->fd, &errval, sizeof(errval));
	write(data->fd, &errval, sizeof(errval));
	kill(os_getpid(), SIGKILL);
	return 0;
}
@@ -92,11 +92,12 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
	 * Read the errno value from the child, if the exec failed, or get 0 if
	 * the exec succeeded because the pipe fd was set as close-on-exec.
	 */
	n = os_read_file(fds[0], &ret, sizeof(ret));
	n = read(fds[0], &ret, sizeof(ret));
	if (n == 0) {
		ret = pid;
	} else {
		if (n < 0) {
			n = -errno;
			printk("run_helper : read on pipe failed, ret = %d\n",
			       -n);
			ret = n;
+2 −3
Original line number Diff line number Diff line
@@ -232,10 +232,9 @@ int __init create_tmp_file(unsigned long long len)

	zero = 0;

	err = os_write_file(fd, &zero, 1);
	err = write(fd, &zero, 1);
	if(err != 1){
		errno = -err;
		perror("os_write_file");
		perror("write");
		exit(1);
	}

+4 −4
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ unsigned long os_process_pc(int pid)
		       proc_stat, -fd);
		return ARBITRARY_ADDR;
	}
	err = os_read_file(fd, buf, sizeof(buf));
	CATCH_EINTR(err = read(fd, buf, sizeof(buf)));
	if(err < 0){
		printk("os_process_pc - couldn't read '%s', err = %d\n",
		       proc_stat, -err);
		       proc_stat, errno);
		os_close_file(fd);
		return ARBITRARY_ADDR;
	}
@@ -75,11 +75,11 @@ int os_process_parent(int pid)
		return FAILURE_PID;
	}

	n = os_read_file(fd, data, sizeof(data));
	CATCH_EINTR(n = read(fd, data, sizeof(data)));
	os_close_file(fd);

	if(n < 0){
		printk("Couldn't read '%s', err = %d\n", stat, -n);
		printk("Couldn't read '%s', err = %d\n", stat, errno);
		return FAILURE_PID;
	}

Loading