#include <poll.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <lustre/lustreapi.h>
+#include <linux/lustre/lustre_ioctl.h>
static int chlg_dev_path(char *path, size_t path_len, const char *device)
struct changelog_private *cp;
static bool warned_extra_flags;
static bool warned_jobid;
- static bool warned_follow;
char cdev_path[PATH_MAX];
int rc;
warned_jobid = true;
}
- /* Behavior expected by CHANGELOG_FLAG_FOLLOW is not implemented, warn
- * the user and ignore it. */
- if (flags & CHANGELOG_FLAG_FOLLOW && !warned_follow) {
- llapi_err_noerrno(LLAPI_MSG_WARN, "warning: %s() called with "
- "CHANGELOG_FLAG_FOLLOW (ignored)", __func__);
- warned_follow = true;
+ if (flags & CHANGELOG_FLAG_FOLLOW) {
+ int rc;
+ rc = ioctl(cp->clp_fd, OBD_IOC_CHLG_POLL, 1);
+ if (rc < 0)
+ llapi_err_noerrno(LLAPI_MSG_ERROR, "can't enable "
+ "CHANGELOG_FLAG_FOLLOW");
}
return 0;
return 0;
}
+int llapi_changelog_in_buf(void *priv)
+{
+ struct changelog_private *cp = priv;
+ if (cp->clp_buf + cp->clp_buf_len > cp->clp_buf_pos)
+ return 1;
+ return 0;
+}
+
int llapi_changelog_clear(const char *mdtname, const char *idstr,
long long endrec)
{
char dev_path[PATH_MAX];
char cmd[64];
size_t cmd_len = sizeof(cmd);
+ char *dashp, *clidp = NULL;
int fd;
int rc;
chlg_dev_path(dev_path, sizeof(dev_path), mdtname);
- rc = snprintf(cmd, cmd_len, "clear:%s:%lld", idstr, endrec);
- if (rc >= sizeof(cmd))
- return -EINVAL;
+ dashp = strchr(idstr, '-');
+ if (dashp) {
+ clidp = strndup(idstr, dashp - idstr);
+ if (!clidp)
+ return -ENOMEM;
+ }
+ rc = snprintf(cmd, cmd_len, "clear:%s:%lld", dashp ? clidp : idstr,
+ endrec);
+ if (rc >= sizeof(cmd)) {
+ rc = -EINVAL;
+ goto out;
+ }
cmd_len = rc + 1;
fd = open(dev_path, O_WRONLY);
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", dev_path);
- return rc;
+ goto out;
}
rc = write(fd, cmd, cmd_len);
out_close:
close(fd);
+out:
+ free(clidp);
return rc;
}