Whamcloud - gitweb
LU-14838 osc: Remove lockless truncate
[fs/lustre-release.git] / lustre / utils / liblustreapi_chlg.c
index 32a31c2..ebb2450 100644 (file)
 #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)
@@ -93,7 +95,6 @@ int llapi_changelog_start(void **priv, enum changelog_send_flag flags,
        struct changelog_private *cp;
        static bool warned_extra_flags;
        static bool warned_jobid;
-       static bool warned_follow;
        char cdev_path[PATH_MAX];
        int rc;
 
@@ -150,12 +151,12 @@ int llapi_changelog_start(void **priv, enum changelog_send_flag flags,
                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;
@@ -249,6 +250,10 @@ int llapi_changelog_recv(void *priv, struct changelog_rec **rech)
                        rec_extra_fmt |= CLFE_UIDGID;
                if (cp->clp_send_extra_flags & CHANGELOG_EXTRA_FLAG_NID)
                        rec_extra_fmt |= CLFE_NID;
+               if (cp->clp_send_extra_flags & CHANGELOG_EXTRA_FLAG_OMODE)
+                       rec_extra_fmt |= CLFE_OPEN;
+               if (cp->clp_send_extra_flags & CHANGELOG_EXTRA_FLAG_XATTR)
+                       rec_extra_fmt |= CLFE_XATTR;
        }
 
        if (cp->clp_buf + cp->clp_buf_len <= cp->clp_buf_pos) {
@@ -290,12 +295,21 @@ int llapi_changelog_free(struct changelog_rec **rech)
        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;
 
@@ -307,17 +321,26 @@ int llapi_changelog_clear(const char *mdtname, const char *idstr,
 
        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);
@@ -332,6 +355,8 @@ int llapi_changelog_clear(const char *mdtname, const char *idstr,
 
 out_close:
        close(fd);
+out:
+       free(clidp);
        return rc;
 }