mirror of https://github.com/schoebel/mars
infra: fix readlink() for very long paths
This commit is contained in:
parent
012292677c
commit
5d2a682cfd
|
@ -735,12 +735,12 @@ int compare_replaylinks(struct mars_rotate *rot, const char *hosta, const char *
|
|||
}
|
||||
|
||||
a = mars_readlink(linka);
|
||||
if (unlikely(!a)) {
|
||||
if (unlikely(!a || !a[0])) {
|
||||
MARS_ERR_TO(rot->log_say, "cannot read replaylink '%s'\n", linka);
|
||||
goto done;
|
||||
}
|
||||
b = mars_readlink(linkb);
|
||||
if (unlikely(!b)) {
|
||||
if (unlikely(!b || !b[0])) {
|
||||
MARS_ERR_TO(rot->log_say, "cannot read replaylink '%s'\n", linkb);
|
||||
goto done;
|
||||
}
|
||||
|
@ -885,7 +885,7 @@ int _update_version_link(struct mars_rotate *rot, struct trans_logger_info *inf)
|
|||
char *msg = "";
|
||||
int skip_nr = -1;
|
||||
int nr_char = 0;
|
||||
if (skip_link) {
|
||||
if (likely(skip_link && skip_link[0])) {
|
||||
(void)sscanf(skip_link, "%d%n", &skip_nr, &nr_char);
|
||||
msg = skip_link + nr_char;
|
||||
}
|
||||
|
@ -920,7 +920,7 @@ int _update_version_link(struct mars_rotate *rot, struct trans_logger_info *inf)
|
|||
len += sprintf(old + len, "%02x", digest[i]);
|
||||
}
|
||||
|
||||
if (likely(prev_link)) {
|
||||
if (likely(prev_link && prev_link[0])) {
|
||||
char *tmp;
|
||||
prev_digest = brick_strdup(prev_link);
|
||||
if (unlikely(!prev_digest)) {
|
||||
|
@ -2083,18 +2083,18 @@ bool is_switchover_possible(struct mars_rotate *rot, const char *old_log_path, c
|
|||
|
||||
// fetch all the versionlinks and test for their existence.
|
||||
own_versionlink = get_versionlink(rot->parent_path, old_log_seq, my_id(), &own_versionlink_path);
|
||||
if (unlikely(!own_versionlink)) {
|
||||
if (unlikely(!own_versionlink || !own_versionlink[0])) {
|
||||
MARS_ERR_TO(rot->log_say, "cannot read my own versionlink '%s'\n", SAFE_STR(own_versionlink_path));
|
||||
goto done;
|
||||
}
|
||||
old_versionlink = get_versionlink(rot->parent_path, old_log_seq, old_host, &old_versionlink_path);
|
||||
if (unlikely(!old_versionlink)) {
|
||||
if (unlikely(!old_versionlink || !old_versionlink[0])) {
|
||||
MARS_ERR_TO(rot->log_say, "cannot read old versionlink '%s'\n", SAFE_STR(old_versionlink_path));
|
||||
goto done;
|
||||
}
|
||||
if (!skip_new) {
|
||||
new_versionlink = get_versionlink(rot->parent_path, new_log_seq, new_host, &new_versionlink_path);
|
||||
if (unlikely(!new_versionlink)) {
|
||||
if (unlikely(!new_versionlink || !new_versionlink[0])) {
|
||||
MARS_INF_TO(rot->log_say, "new versionlink '%s' does not yet exist, we must wait for it.\n", SAFE_STR(new_versionlink_path));
|
||||
goto done;
|
||||
}
|
||||
|
@ -2108,7 +2108,7 @@ bool is_switchover_possible(struct mars_rotate *rot, const char *old_log_path, c
|
|||
|
||||
// check: did I fully apply my old logfile data?
|
||||
own_replaylink = get_replaylink(rot->parent_path, my_id(), &own_replaylink_path);
|
||||
if (unlikely(!own_replaylink)) {
|
||||
if (unlikely(!own_replaylink || !own_replaylink[0])) {
|
||||
MARS_ERR_TO(rot->log_say, "cannot read my own replaylink '%s'\n", SAFE_STR(own_replaylink_path));
|
||||
goto done;
|
||||
}
|
||||
|
@ -3615,7 +3615,7 @@ int _update_syncstatus(struct mars_rotate *rot, struct copy_brick *copy, char *p
|
|||
mars_stat(dst, &syncstatus_stat, true) >= 0 &&
|
||||
mars_stat(peer_replay_path, &peer_replay_stat, true) >= 0 &&
|
||||
timespec_compare(&syncstatus_stat.mtime, &peer_replay_stat.mtime) <= 0 &&
|
||||
(peer_replay_link = mars_readlink(peer_replay_path)) &&
|
||||
(peer_replay_link = mars_readlink(peer_replay_path)) && peer_replay_link[0] &&
|
||||
(mars_stat(syncpos_path, &syncpos_stat, true) < 0 ||
|
||||
timespec_compare(&syncpos_stat.mtime, &syncstatus_stat.mtime) < 0)) {
|
||||
_update_link_when_necessary(rot, "syncpos", peer_replay_link, syncpos_path);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#define MARS_ARGV_MAX 4
|
||||
#define MARS_PATH_MAX 256
|
||||
#define MARS_SYMLINK_MAX 1023
|
||||
|
||||
extern loff_t global_total_space;
|
||||
extern loff_t global_remaining_space;
|
||||
|
|
|
@ -193,7 +193,7 @@ EXPORT_SYMBOL_GPL(mars_symlink);
|
|||
|
||||
char *mars_readlink(const char *newpath)
|
||||
{
|
||||
char *res = brick_string_alloc(1024);
|
||||
char *res = brick_string_alloc(MARS_SYMLINK_MAX + 1);
|
||||
struct path path = {};
|
||||
mm_segment_t oldfs;
|
||||
struct inode *inode;
|
||||
|
@ -218,7 +218,7 @@ char *mars_readlink(const char *newpath)
|
|||
goto done_put;
|
||||
}
|
||||
|
||||
status = inode->i_op->readlink(path.dentry, res, 1024);
|
||||
status = inode->i_op->readlink(path.dentry, res, MARS_SYMLINK_MAX);
|
||||
if (unlikely(status < 0)) {
|
||||
MARS_ERR("cannot read link '%s', status = %d\n", newpath, status);
|
||||
} else {
|
||||
|
@ -232,8 +232,7 @@ done_fs:
|
|||
set_fs(oldfs);
|
||||
done:
|
||||
if (unlikely(status < 0)) {
|
||||
brick_string_free(res);
|
||||
res = NULL;
|
||||
res[0] = '\0';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1414,10 +1413,10 @@ EXPORT_SYMBOL_GPL(mars_kill_brick_when_possible);
|
|||
|
||||
char *_vpath_make(int line, const char *fmt, va_list *args)
|
||||
{
|
||||
char *res = _brick_string_alloc(MARS_PATH_MAX, line);
|
||||
char *res = _brick_string_alloc(MARS_SYMLINK_MAX, line);
|
||||
|
||||
if (likely(res)) {
|
||||
vsnprintf(res, MARS_PATH_MAX, fmt, *args);
|
||||
vsnprintf(res, MARS_SYMLINK_MAX, fmt, *args);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1437,7 +1436,7 @@ EXPORT_SYMBOL_GPL(_path_make);
|
|||
char *_backskip_replace(int line, const char *path, char delim, bool insert, const char *fmt, ...)
|
||||
{
|
||||
int path_len = strlen(path);
|
||||
int total_len = strlen(fmt) + path_len + MARS_PATH_MAX;
|
||||
int total_len = strlen(fmt) + path_len + MARS_SYMLINK_MAX;
|
||||
char *res = _brick_string_alloc(total_len + 1, line);
|
||||
if (likely(res)) {
|
||||
va_list args;
|
||||
|
|
Loading…
Reference in New Issue