Skip to content

Commit

Permalink
zed: replace zed_file_write_n() with write(2), purge it
Browse files Browse the repository at this point in the history
We set SA_RESTART early on, which will prevent EINTRs (indeed, to the
point of needing to clear it in the reaper, since it interferes with
pause(2)), which is the only error zed_file_write_n() actually handled
(plus, the pid write is no bigger than 12 bytes anyway)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#11834
  • Loading branch information
nabijaczleweli authored and mcmilk committed Apr 10, 2021
1 parent 56eb517 commit 121398f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 30 deletions.
2 changes: 1 addition & 1 deletion cmd/zed/zed_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ zed_conf_write_pid(struct zed_conf *zcp)
errno = ERANGE;
zed_log_msg(LOG_ERR, "Failed to write PID file \"%s\": %s",
zcp->pid_file, strerror(errno));
} else if (zed_file_write_n(zcp->pid_fd, buf, n) != n) {
} else if (write(zcp->pid_fd, buf, n) != n) {
zed_log_msg(LOG_ERR, "Failed to write PID file \"%s\": %s",
zcp->pid_file, strerror(errno));
} else if (fdatasync(zcp->pid_fd) < 0) {
Expand Down
27 changes: 0 additions & 27 deletions cmd/zed/zed_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,6 @@
#include "zed_file.h"
#include "zed_log.h"

/*
* Write [n] bytes from [buf] out to [fd].
* Return the number of bytes written, or -1 on error.
*/
ssize_t
zed_file_write_n(int fd, void *buf, size_t n)
{
const unsigned char *p;
size_t n_left;
ssize_t n_written;

p = buf;
n_left = n;
while (n_left > 0) {
if ((n_written = write(fd, p, n_left)) < 0) {
if (errno == EINTR)
continue;
else
return (-1);

}
n_left -= n_written;
p += n_written;
}
return (n);
}

/*
* Set an exclusive advisory lock on the open file descriptor [fd].
* Return 0 on success, 1 if a conflicting lock is held by another process,
Expand Down
2 changes: 0 additions & 2 deletions cmd/zed/zed_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <sys/types.h>
#include <unistd.h>

ssize_t zed_file_write_n(int fd, void *buf, size_t n);

int zed_file_lock(int fd);

int zed_file_unlock(int fd);
Expand Down

0 comments on commit 121398f

Please sign in to comment.