diff options
author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2015-10-01 16:16:52 -0400 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2015-10-28 16:34:45 -0700 |
commit | 36ea43b93b8476595ac22da031bc42a807ccc852 (patch) | |
tree | 314c44d79bdaea5f8e91676d0996b9313b5a843b /xlators/features/changelog | |
parent | 323e71617fee5020324540776d0d4469577f0afe (diff) |
core: use syscall wrappers instead of direct syscalls
various xlators and other components are invoking system calls
directly instead of using the libglusterfs/syscall.[ch] wrappers.
If not using the system call wrappers there should be a comment
in the source explaining why the wrapper isn't used.
Change-Id: I8ef94c48728666465abf126c778b70c9e5c00e47
BUG: 1267967
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: http://review.gluster.org/12273
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/features/changelog')
9 files changed, 63 insertions, 52 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog-api.c b/xlators/features/changelog/lib/src/gf-changelog-api.c index 63c0098d248..f41b505a749 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-api.c +++ b/xlators/features/changelog/lib/src/gf-changelog-api.c @@ -11,6 +11,7 @@ #include "compat-uuid.h" #include "globals.h" #include "glusterfs.h" +#include "syscall.h" #include "gf-changelog-helpers.h" #include "gf-changelog-journal.h" @@ -52,7 +53,7 @@ gf_changelog_done (char *file) jnl->jnl_processed_dir, basename (buffer)); gf_msg_debug (this->name, 0, "moving %s to processed directory", file); - ret = rename (buffer, to_path); + ret = sys_rename (buffer, to_path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.c b/xlators/features/changelog/lib/src/gf-changelog-helpers.c index d6245743437..8b35f4e9416 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-helpers.c +++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.c @@ -11,10 +11,11 @@ #include "changelog-mem-types.h" #include "gf-changelog-helpers.h" #include "changelog-lib-messages.h" +#include "syscall.h" ssize_t gf_changelog_read_path (int fd, char *buffer, size_t bufsize) { - return read (fd, buffer, bufsize); + return sys_read (fd, buffer, bufsize); } size_t @@ -24,8 +25,7 @@ gf_changelog_write (int fd, char *buffer, size_t len) size_t written = 0; while (written < len) { - size = write (fd, - buffer + written, len - written); + size = sys_write (fd, buffer + written, len - written); if (size <= 0) break; @@ -81,7 +81,9 @@ static ssize_t my_read (read_line_t *tsd, int fd, char *ptr) { if (tsd->rl_cnt <= 0) { - if ( (tsd->rl_cnt = read (fd, tsd->rl_buf, MAXLINE)) < 0 ) + tsd->rl_cnt = sys_read (fd, tsd->rl_buf, MAXLINE); + + if (tsd->rl_cnt < 0) return -1; else if (tsd->rl_cnt == 0) return 0; @@ -154,7 +156,8 @@ gf_lseek (int fd, off_t offset, int whence) if (gf_readline_init_once (&tsd)) return -1; - if ( (off = lseek (fd, offset, whence)) == -1) + off = sys_lseek (fd, offset, whence); + if (off == -1) return -1; tsd->rl_cnt = 0; @@ -171,7 +174,7 @@ gf_ftruncate (int fd, off_t length) if (gf_readline_init_once (&tsd)) return -1; - if (ftruncate (fd, 0)) + if (sys_ftruncate (fd, 0)) return -1; tsd->rl_cnt = 0; diff --git a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c index f04117298a9..6ea7cac88da 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c +++ b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c @@ -11,6 +11,7 @@ #include "compat-uuid.h" #include "globals.h" #include "glusterfs.h" +#include "syscall.h" #include "compat-errno.h" #include "gf-changelog-helpers.h" @@ -440,7 +441,7 @@ gf_changelog_copy (xlator_t *this, int from_fd, int to_fd) char buffer[COPY_BUFSIZE+1] = {0,}; while (1) { - size = read (from_fd, buffer, COPY_BUFSIZE); + size = sys_read (from_fd, buffer, COPY_BUFSIZE); if (size <= 0) break; @@ -500,7 +501,7 @@ gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl, /** * start processing after the header */ - lseek (from_fd, elen, SEEK_SET); + sys_lseek (from_fd, elen, SEEK_SET); switch (encoding) { case CHANGELOG_ENCODE_BINARY: @@ -539,7 +540,7 @@ gf_changelog_publish (xlator_t *this, jnl->jnl_current_dir, basename (from_path)); /* handle zerob file that wont exist in current */ - ret = stat (to_path, &stbuf); + ret = sys_stat (to_path, &stbuf); if (ret) { if (errno == ENOENT) ret = 0; @@ -549,7 +550,7 @@ gf_changelog_publish (xlator_t *this, (void) snprintf (dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir, basename (from_path)); - ret = rename (to_path, dest); + ret = sys_rename (to_path, dest); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, @@ -574,7 +575,7 @@ gf_changelog_consume (xlator_t *this, char dest[PATH_MAX] = {0,}; char to_path[PATH_MAX] = {0,}; - ret = stat (from_path, &stbuf); + ret = sys_stat (from_path, &stbuf); if (ret || !S_ISREG(stbuf.st_mode)) { ret = -1; gf_msg (this->name, GF_LOG_ERROR, errno, @@ -609,14 +610,14 @@ gf_changelog_consume (xlator_t *this, ret = gf_changelog_decode (this, jnl, fd1, fd2, &stbuf, &zerob); - close (fd2); + sys_close (fd2); if (!ret) { /* move it to processing on a successful decode */ if (no_publish == _gf_true) goto close_fd; - ret = rename (to_path, dest); + ret = sys_rename (to_path, dest); if (ret) gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, @@ -627,7 +628,7 @@ gf_changelog_consume (xlator_t *this, /* remove it from .current if it's an empty file */ if (zerob) { /* zerob changelogs must be unlinked */ - ret = unlink (to_path); + ret = sys_unlink (to_path); if (ret) gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_UNLINK_FAILED, @@ -637,7 +638,7 @@ gf_changelog_consume (xlator_t *this, } close_fd: - close (fd1); + sys_close (fd1); out: return ret; @@ -830,10 +831,10 @@ gf_changelog_cleanup_fds (gf_changelog_journal_t *jnl) { /* tracker fd */ if (jnl->jnl_fd != -1) - close (jnl->jnl_fd); + sys_close (jnl->jnl_fd); /* processing dir */ if (jnl->jnl_dir) - closedir (jnl->jnl_dir); + sys_closedir (jnl->jnl_dir); if (jnl->jnl_working_dir) free (jnl->jnl_working_dir); /* allocated by realpath */ @@ -888,7 +889,7 @@ gf_changelog_open_dirs (xlator_t *this, gf_changelog_journal_t *jnl) if (ret) goto out; - dir = opendir (jnl->jnl_processing_dir); + dir = sys_opendir (jnl->jnl_processing_dir); if (!dir) { gf_msg ("", GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPENDIR_ERROR, @@ -904,7 +905,7 @@ gf_changelog_open_dirs (xlator_t *this, gf_changelog_journal_t *jnl) tracker_fd = open (tracker_path, O_CREAT | O_APPEND | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (tracker_fd < 0) { - closedir (jnl->jnl_dir); + sys_closedir (jnl->jnl_dir); ret = -1; goto out; } @@ -1007,7 +1008,7 @@ gf_changelog_journal_init (void *xl, struct gf_brick_spec *brick) if (!jnl) goto error_return; - if (stat (scratch_dir, &buf) && errno == ENOENT) { + if (sys_stat (scratch_dir, &buf) && errno == ENOENT) { ret = mkdir_p (scratch_dir, 0600, _gf_true); if (ret) goto dealloc_private; diff --git a/xlators/features/changelog/lib/src/gf-changelog-reborp.c b/xlators/features/changelog/lib/src/gf-changelog-reborp.c index 665a6d0a5da..4c49e9a533f 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-reborp.c +++ b/xlators/features/changelog/lib/src/gf-changelog-reborp.c @@ -15,6 +15,8 @@ #include "changelog-rpc-common.h" #include "changelog-lib-messages.h" +#include "syscall.h" + /** * Reverse socket: actual data transfer handler. Connection * initiator is PROBER, data transfer is REBORP. @@ -113,7 +115,7 @@ gf_changelog_reborp_rpcsvc_notify (rpcsvc_t *rpc, void *mydata, switch (event) { case RPCSVC_EVENT_ACCEPT: - ret = unlink (RPC_SOCK(entry)); + ret = sys_unlink (RPC_SOCK(entry)); if (ret != 0) gf_msg (this->name, GF_LOG_WARNING, errno, CHANGELOG_LIB_MSG_UNLINK_FAILED, diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c index fffe48780c1..f7b58f5a965 100644 --- a/xlators/features/changelog/lib/src/gf-history-changelog.c +++ b/xlators/features/changelog/lib/src/gf-history-changelog.c @@ -75,7 +75,7 @@ gf_history_changelog_done (char *file) hist_jnl->jnl_processed_dir, basename (buffer)); gf_msg_debug (this->name, 0, "moving %s to processed directory", file); - ret = rename (buffer, to_path); + ret = sys_rename (buffer, to_path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, @@ -678,7 +678,7 @@ gf_history_consume (void * data) out: if (fd != -1) - close (fd); + sys_close (fd); GF_FREE (hist_data); return NULL; } @@ -728,7 +728,7 @@ gf_changelog_extract_min_max (const char *dname, const char *htime_dir, iter = (htime_file + strlen (htime_file) - TIMESTAMP_LENGTH); sscanf (iter ,"%lu",min_ts); - ret = stat (htime_file, &stbuf); + ret = sys_stat (htime_file, &stbuf); if (ret) { ret = -1; gf_msg (this->name, GF_LOG_ERROR, errno, @@ -841,7 +841,7 @@ gf_history_changelog (char* changelog_dir, unsigned long start, CHANGELOG_FILL_HTIME_DIR (changelog_dir, htime_dir); - dirp = opendir (htime_dir); + dirp = sys_opendir (htime_dir); if (dirp == NULL) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR, @@ -851,7 +851,7 @@ gf_history_changelog (char* changelog_dir, unsigned long start, goto out; } - while ((dp = readdir (dirp)) != NULL) { + while ((dp = sys_readdir (dirp)) != NULL) { ret = gf_changelog_extract_min_max (dp->d_name, htime_dir, &fd, &total_changelog, &min_ts, &max_ts); @@ -865,7 +865,7 @@ gf_history_changelog (char* changelog_dir, unsigned long start, /** * TODO: handle short reads later... */ - n_read = read (fd, buffer, PATH_MAX); + n_read = sys_read (fd, buffer, PATH_MAX); if (n_read < 0) { ret = -1; gf_msg (this->name, GF_LOG_ERROR, errno, @@ -968,11 +968,11 @@ gf_history_changelog (char* changelog_dir, unsigned long start, out: if (dirp != NULL) - closedir (dirp); + sys_closedir (dirp); if (ret < 0) { if (fd != -1) - close (fd); + sys_close (fd); GF_FREE (hist_data); (void) pthread_attr_destroy (&attr); diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c index 6ca77e990cc..e352f2ec859 100644 --- a/xlators/features/changelog/src/changelog-helpers.c +++ b/xlators/features/changelog/src/changelog-helpers.c @@ -262,7 +262,7 @@ changelog_write (int fd, char *buffer, size_t len) size_t written = 0; while (written < len) { - size = write (fd, + size = sys_write (fd, buffer + written, len - written); if (size <= 0) break; @@ -303,7 +303,8 @@ htime_update (xlator_t *this, goto out; } - sprintf (x_value,"%lu:%d",ts, priv->rollover_count); + snprintf (x_value, sizeof x_value, "%lu:%d", + ts, priv->rollover_count); if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value, strlen (x_value), XATTR_REPLACE)) { @@ -348,7 +349,7 @@ cl_is_empty (xlator_t *this, int fd) int major_version = -1; int minor_version = -1; - ret = fstat (fd, &stbuf); + ret = sys_fstat (fd, &stbuf); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSTAT_OP_FAILED, @@ -356,7 +357,7 @@ cl_is_empty (xlator_t *this, int fd) goto out; } - ret = lseek (fd, 0, SEEK_SET); + ret = sys_lseek (fd, 0, SEEK_SET); if (ret == -1) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_LSEEK_OP_FAILED, @@ -422,7 +423,7 @@ changelog_rollover_changelog (xlator_t *this, changelog_event_t ev = {0,}; if (priv->changelog_fd != -1) { - ret = fsync (priv->changelog_fd); + ret = sys_fsync (priv->changelog_fd); if (ret < 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, @@ -437,7 +438,7 @@ changelog_rollover_changelog (xlator_t *this, CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED, "Error detecting empty changelog"); } - close (priv->changelog_fd); + sys_close (priv->changelog_fd); priv->changelog_fd = -1; } @@ -448,7 +449,7 @@ changelog_rollover_changelog (xlator_t *this, priv->changelog_dir, ts); if (cl_empty_flag == 1) { - ret = unlink (ofile); + ret = sys_unlink (ofile); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_UNLINK_OP_FAILED, @@ -459,7 +460,7 @@ changelog_rollover_changelog (xlator_t *this, reset return value to 0*/ } } else { - ret = rename (ofile, nfile); + ret = sys_rename (ofile, nfile); if (ret && (errno == ENOENT)) { ret = 0; @@ -584,7 +585,7 @@ find_current_htime (int ht_dir_fd, const char *ht_dir_path, char *ht_file_bname) goto out; } - if (fsync (ht_dir_fd) < 0) { + if (sys_fsync (ht_dir_fd) < 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, "fsync failed"); @@ -704,7 +705,7 @@ htime_open (xlator_t *this, out: if (ht_dir_fd != -1) - close (ht_dir_fd); + sys_close (ht_dir_fd); return ret; } @@ -754,7 +755,7 @@ htime_create (xlator_t *this, goto out; } - ret = fsync (ht_file_fd); + ret = sys_fsync (ht_file_fd); if (ret < 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, @@ -783,7 +784,7 @@ htime_create (xlator_t *this, goto out; } - ret = fsync (ht_dir_fd); + ret = sys_fsync (ht_dir_fd); if (ret < 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, @@ -798,7 +799,7 @@ htime_create (xlator_t *this, out: if (ht_dir_fd != -1) - close (ht_dir_fd); + sys_close (ht_dir_fd); return ret; } @@ -846,7 +847,7 @@ changelog_snap_open (xlator_t *this, priv->ce->encoder); ret = changelog_snap_write_change (priv, buffer, strlen (buffer)); if (ret < 0) { - close (priv->c_snap_fd); + sys_close (priv->c_snap_fd); priv->c_snap_fd = -1; goto out; } @@ -889,7 +890,7 @@ changelog_snap_logging_stop (xlator_t *this, { int ret = 0; - close (priv->c_snap_fd); + sys_close (priv->c_snap_fd); priv->c_snap_fd = -1; gf_msg (this->name, GF_LOG_INFO, 0, @@ -936,7 +937,7 @@ changelog_open_journal (xlator_t *this, priv->ce->encoder); ret = changelog_write_change (priv, buffer, strlen (buffer)); if (ret) { - close (priv->changelog_fd); + sys_close (priv->changelog_fd); priv->changelog_fd = -1; goto out; } @@ -1080,7 +1081,7 @@ changelog_handle_change (xlator_t *this, return 0; if (CHANGELOG_TYPE_IS_FSYNC (cld->cld_type)) { - ret = fsync (priv->changelog_fd); + ret = sys_fsync (priv->changelog_fd); if (ret < 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED, @@ -1302,7 +1303,7 @@ changelog_rollover (void *data) gf_msg (this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO, "Explicit wakeup of select on barrier notify"); - len = read(priv->cr.rfd, buf, 1); + len = sys_read (priv->cr.rfd, buf, 1); if (len == 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_READ_ERROR, "BUG: Got EOF" @@ -1955,7 +1956,7 @@ resolve_pargfid_to_path (xlator_t *this, uuid_t pargfid, snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath, pargfid[0], pargfid[1], uuid_utoa (pargfid)); - len = readlink (dir_handle, linkname, PATH_MAX); + len = sys_readlink (dir_handle, linkname, PATH_MAX); if (len < 0) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_READLINK_OP_FAILED, diff --git a/xlators/features/changelog/src/changelog-misc.h b/xlators/features/changelog/src/changelog-misc.h index c0349ca3838..778f79c82c5 100644 --- a/xlators/features/changelog/src/changelog-misc.h +++ b/xlators/features/changelog/src/changelog-misc.h @@ -80,7 +80,7 @@ } \ fclose (fp); \ } else { \ - close (fd_dup); \ + sys_close (fd_dup); \ } \ } \ } while (0) diff --git a/xlators/features/changelog/src/changelog-rpc-common.c b/xlators/features/changelog/src/changelog-rpc-common.c index e8905a87f62..4525923d34d 100644 --- a/xlators/features/changelog/src/changelog-rpc-common.c +++ b/xlators/features/changelog/src/changelog-rpc-common.c @@ -10,6 +10,8 @@ #include "changelog-rpc-common.h" #include "changelog-messages.h" + +#include "syscall.h" /** ***************************************************** Client Interface @@ -271,7 +273,7 @@ changelog_rpc_server_destroy (xlator_t *this, rpcsvc_t *rpc, char *sockfile, } (void) rpcsvc_unregister_notify (rpc, fn, this); - unlink (sockfile); + sys_unlink (sockfile); GF_FREE (rpc); } diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c index 08ef67dd65d..c954e5e0616 100644 --- a/xlators/features/changelog/src/changelog.c +++ b/xlators/features/changelog/src/changelog.c @@ -10,6 +10,7 @@ #include "xlator.h" #include "defaults.h" +#include "syscall.h" #include "logging.h" #include "iobuf.h" @@ -1918,7 +1919,7 @@ changelog_cleanup_helper_threads (xlator_t *this, changelog_priv_t *priv) if (priv->cr.rollover_th) { (void) changelog_thread_cleanup (this, priv->cr.rollover_th); priv->cr.rollover_th = 0; - ret = close (priv->cr_wfd); + ret = sys_close (priv->cr_wfd); if (ret) gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_CLOSE_ERROR, |