render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0068-virtiofsd-print-log-only-when-priority-is-high-enoug.patch

1d442b
From: Eryu Guan <eguan@linux.alibaba.com>
1d442b
Date: Mon, 27 Jan 2020 19:01:37 +0000
1d442b
Subject: [PATCH] virtiofsd: print log only when priority is high enough
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
Introduce "-o log_level=" command line option to specify current log
1d442b
level (priority), valid values are "debug info warn err", e.g.
1d442b
1d442b
    ./virtiofsd -o log_level=debug ...
1d442b
1d442b
So only log priority higher than "debug" will be printed to
1d442b
stderr/syslog. And the default level is info.
1d442b
1d442b
The "-o debug"/"-d" options are kept, and imply debug log level.
1d442b
1d442b
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
1d442b
dgilbert: Reworked for libfuse's log_func
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
with fix by:
1d442b
Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
1d442b
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit d240314a1a18a1d914af1b5763fe8c9a572e6409)
1d442b
---
1d442b
 tools/virtiofsd/fuse_lowlevel.c  |  75 ++++++++------------
1d442b
 tools/virtiofsd/fuse_lowlevel.h  |   1 +
1d442b
 tools/virtiofsd/helper.c         |   8 ++-
1d442b
 tools/virtiofsd/passthrough_ll.c | 118 +++++++++++++------------------
1d442b
 4 files changed, 87 insertions(+), 115 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
1d442b
index 6ceb33d913..a7a19685b5 100644
1d442b
--- a/tools/virtiofsd/fuse_lowlevel.c
1d442b
+++ b/tools/virtiofsd/fuse_lowlevel.c
1d442b
@@ -158,19 +158,17 @@ static int fuse_send_msg(struct fuse_session *se, struct fuse_chan *ch,
1d442b
     struct fuse_out_header *out = iov[0].iov_base;
1d442b
 
1d442b
     out->len = iov_length(iov, count);
1d442b
-    if (se->debug) {
1d442b
-        if (out->unique == 0) {
1d442b
-            fuse_log(FUSE_LOG_DEBUG, "NOTIFY: code=%d length=%u\n", out->error,
1d442b
-                     out->len);
1d442b
-        } else if (out->error) {
1d442b
-            fuse_log(FUSE_LOG_DEBUG,
1d442b
-                     "   unique: %llu, error: %i (%s), outsize: %i\n",
1d442b
-                     (unsigned long long)out->unique, out->error,
1d442b
-                     strerror(-out->error), out->len);
1d442b
-        } else {
1d442b
-            fuse_log(FUSE_LOG_DEBUG, "   unique: %llu, success, outsize: %i\n",
1d442b
-                     (unsigned long long)out->unique, out->len);
1d442b
-        }
1d442b
+    if (out->unique == 0) {
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "NOTIFY: code=%d length=%u\n", out->error,
1d442b
+                 out->len);
1d442b
+    } else if (out->error) {
1d442b
+        fuse_log(FUSE_LOG_DEBUG,
1d442b
+                 "   unique: %llu, error: %i (%s), outsize: %i\n",
1d442b
+                 (unsigned long long)out->unique, out->error,
1d442b
+                 strerror(-out->error), out->len);
1d442b
+    } else {
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "   unique: %llu, success, outsize: %i\n",
1d442b
+                 (unsigned long long)out->unique, out->len);
1d442b
     }
1d442b
 
1d442b
     if (fuse_lowlevel_is_virtio(se)) {
1d442b
@@ -1662,10 +1660,8 @@ static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid,
1d442b
         return;
1d442b
     }
1d442b
 
1d442b
-    if (se->debug) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "INTERRUPT: %llu\n",
1d442b
-                 (unsigned long long)arg->unique);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "INTERRUPT: %llu\n",
1d442b
+             (unsigned long long)arg->unique);
1d442b
 
1d442b
     req->u.i.unique = arg->unique;
1d442b
 
1d442b
@@ -1901,13 +1897,10 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid,
1d442b
         }
1d442b
     }
1d442b
 
1d442b
-    if (se->debug) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "INIT: %u.%u\n", arg->major, arg->minor);
1d442b
-        if (arg->major == 7 && arg->minor >= 6) {
1d442b
-            fuse_log(FUSE_LOG_DEBUG, "flags=0x%08x\n", arg->flags);
1d442b
-            fuse_log(FUSE_LOG_DEBUG, "max_readahead=0x%08x\n",
1d442b
-                     arg->max_readahead);
1d442b
-        }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "INIT: %u.%u\n", arg->major, arg->minor);
1d442b
+    if (arg->major == 7 && arg->minor >= 6) {
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "flags=0x%08x\n", arg->flags);
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "max_readahead=0x%08x\n", arg->max_readahead);
1d442b
     }
1d442b
     se->conn.proto_major = arg->major;
1d442b
     se->conn.proto_minor = arg->minor;
1d442b
@@ -2116,19 +2109,14 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid,
1d442b
     outarg.congestion_threshold = se->conn.congestion_threshold;
1d442b
     outarg.time_gran = se->conn.time_gran;
1d442b
 
1d442b
-    if (se->debug) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "   INIT: %u.%u\n", outarg.major,
1d442b
-                 outarg.minor);
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "   flags=0x%08x\n", outarg.flags);
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "   max_readahead=0x%08x\n",
1d442b
-                 outarg.max_readahead);
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "   max_write=0x%08x\n", outarg.max_write);
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "   max_background=%i\n",
1d442b
-                 outarg.max_background);
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "   congestion_threshold=%i\n",
1d442b
-                 outarg.congestion_threshold);
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "   time_gran=%u\n", outarg.time_gran);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "   INIT: %u.%u\n", outarg.major, outarg.minor);
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "   flags=0x%08x\n", outarg.flags);
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "   max_readahead=0x%08x\n", outarg.max_readahead);
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "   max_write=0x%08x\n", outarg.max_write);
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "   max_background=%i\n", outarg.max_background);
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "   congestion_threshold=%i\n",
1d442b
+             outarg.congestion_threshold);
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "   time_gran=%u\n", outarg.time_gran);
1d442b
 
1d442b
     send_reply_ok(req, &outarg, outargsize);
1d442b
 }
1d442b
@@ -2407,14 +2395,11 @@ void fuse_session_process_buf_int(struct fuse_session *se,
1d442b
     in = fuse_mbuf_iter_advance(&iter, sizeof(*in));
1d442b
     assert(in); /* caller guarantees the input buffer is large enough */
1d442b
 
1d442b
-    if (se->debug) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG,
1d442b
-                 "unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, "
1d442b
-                 "pid: %u\n",
1d442b
-                 (unsigned long long)in->unique,
1d442b
-                 opname((enum fuse_opcode)in->opcode), in->opcode,
1d442b
-                 (unsigned long long)in->nodeid, buf->size, in->pid);
1d442b
-    }
1d442b
+    fuse_log(
1d442b
+        FUSE_LOG_DEBUG,
1d442b
+        "unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, pid: %u\n",
1d442b
+        (unsigned long long)in->unique, opname((enum fuse_opcode)in->opcode),
1d442b
+        in->opcode, (unsigned long long)in->nodeid, buf->size, in->pid);
1d442b
 
1d442b
     req = fuse_ll_alloc_req(se);
1d442b
     if (req == NULL) {
1d442b
diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowlevel.h
1d442b
index f2750bc189..138041e5f1 100644
1d442b
--- a/tools/virtiofsd/fuse_lowlevel.h
1d442b
+++ b/tools/virtiofsd/fuse_lowlevel.h
1d442b
@@ -1796,6 +1796,7 @@ struct fuse_cmdline_opts {
1d442b
     int show_help;
1d442b
     int print_capabilities;
1d442b
     int syslog;
1d442b
+    int log_level;
1d442b
     unsigned int max_idle_threads;
1d442b
 };
1d442b
 
1d442b
diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c
1d442b
index 9692ef9f1f..6d50a46a7e 100644
1d442b
--- a/tools/virtiofsd/helper.c
1d442b
+++ b/tools/virtiofsd/helper.c
1d442b
@@ -34,7 +34,6 @@
1d442b
         t, offsetof(struct fuse_cmdline_opts, p), v \
1d442b
     }
1d442b
 
1d442b
-
1d442b
 static const struct fuse_opt fuse_helper_opts[] = {
1d442b
     FUSE_HELPER_OPT("-h", show_help),
1d442b
     FUSE_HELPER_OPT("--help", show_help),
1d442b
@@ -55,6 +54,10 @@ static const struct fuse_opt fuse_helper_opts[] = {
1d442b
     FUSE_OPT_KEY("subtype=", FUSE_OPT_KEY_KEEP),
1d442b
     FUSE_HELPER_OPT("max_idle_threads=%u", max_idle_threads),
1d442b
     FUSE_HELPER_OPT("--syslog", syslog),
1d442b
+    FUSE_HELPER_OPT_VALUE("log_level=debug", log_level, FUSE_LOG_DEBUG),
1d442b
+    FUSE_HELPER_OPT_VALUE("log_level=info", log_level, FUSE_LOG_INFO),
1d442b
+    FUSE_HELPER_OPT_VALUE("log_level=warn", log_level, FUSE_LOG_WARNING),
1d442b
+    FUSE_HELPER_OPT_VALUE("log_level=err", log_level, FUSE_LOG_ERR),
1d442b
     FUSE_OPT_END
1d442b
 };
1d442b
 
1d442b
@@ -142,6 +145,9 @@ void fuse_cmdline_help(void)
1d442b
            "    --syslog                   log to syslog (default stderr)\n"
1d442b
            "    -f                         foreground operation\n"
1d442b
            "    --daemonize                run in background\n"
1d442b
+           "    -o log_level=<level>       log level, default to \"info\"\n"
1d442b
+           "                               level could be one of \"debug, "
1d442b
+           "info, warn, err\"\n"
1d442b
            "    -o max_idle_threads        the maximum number of idle worker "
1d442b
            "threads\n"
1d442b
            "                               allowed (default: 10)\n"
1d442b
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
1d442b
index 0372aca143..ff6910fd73 100644
1d442b
--- a/tools/virtiofsd/passthrough_ll.c
1d442b
+++ b/tools/virtiofsd/passthrough_ll.c
1d442b
@@ -37,6 +37,7 @@
1d442b
 
1d442b
 #include "qemu/osdep.h"
1d442b
 #include "fuse_virtio.h"
1d442b
+#include "fuse_log.h"
1d442b
 #include "fuse_lowlevel.h"
1d442b
 #include <assert.h>
1d442b
 #include <cap-ng.h>
1d442b
@@ -140,6 +141,7 @@ static const struct fuse_opt lo_opts[] = {
1d442b
     FUSE_OPT_END
1d442b
 };
1d442b
 static bool use_syslog = false;
1d442b
+static int current_log_level;
1d442b
 
1d442b
 static void unref_inode(struct lo_data *lo, struct lo_inode *inode, uint64_t n);
1d442b
 
1d442b
@@ -458,11 +460,6 @@ static int lo_fd(fuse_req_t req, fuse_ino_t ino)
1d442b
     return inode ? inode->fd : -1;
1d442b
 }
1d442b
 
1d442b
-static bool lo_debug(fuse_req_t req)
1d442b
-{
1d442b
-    return lo_data(req)->debug != 0;
1d442b
-}
1d442b
-
1d442b
 static void lo_init(void *userdata, struct fuse_conn_info *conn)
1d442b
 {
1d442b
     struct lo_data *lo = (struct lo_data *)userdata;
1d442b
@@ -472,15 +469,11 @@ static void lo_init(void *userdata, struct fuse_conn_info *conn)
1d442b
     }
1d442b
 
1d442b
     if (lo->writeback && conn->capable & FUSE_CAP_WRITEBACK_CACHE) {
1d442b
-        if (lo->debug) {
1d442b
-            fuse_log(FUSE_LOG_DEBUG, "lo_init: activating writeback\n");
1d442b
-        }
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "lo_init: activating writeback\n");
1d442b
         conn->want |= FUSE_CAP_WRITEBACK_CACHE;
1d442b
     }
1d442b
     if (lo->flock && conn->capable & FUSE_CAP_FLOCK_LOCKS) {
1d442b
-        if (lo->debug) {
1d442b
-            fuse_log(FUSE_LOG_DEBUG, "lo_init: activating flock locks\n");
1d442b
-        }
1d442b
+        fuse_log(FUSE_LOG_DEBUG, "lo_init: activating flock locks\n");
1d442b
         conn->want |= FUSE_CAP_FLOCK_LOCKS;
1d442b
     }
1d442b
 }
1d442b
@@ -823,10 +816,8 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
     }
1d442b
     e->ino = inode->fuse_ino;
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n",
1d442b
-                 (unsigned long long)parent, name, (unsigned long long)e->ino);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n", (unsigned long long)parent,
1d442b
+             name, (unsigned long long)e->ino);
1d442b
 
1d442b
     return 0;
1d442b
 
1d442b
@@ -843,10 +834,8 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
1d442b
     struct fuse_entry_param e;
1d442b
     int err;
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "lo_lookup(parent=%" PRIu64 ", name=%s)\n",
1d442b
-                 parent, name);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_lookup(parent=%" PRIu64 ", name=%s)\n", parent,
1d442b
+             name);
1d442b
 
1d442b
     /*
1d442b
      * Don't use is_safe_path_component(), allow "." and ".." for NFS export
1d442b
@@ -971,10 +960,8 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
1d442b
         goto out;
1d442b
     }
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n",
1d442b
-                 (unsigned long long)parent, name, (unsigned long long)e.ino);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n", (unsigned long long)parent,
1d442b
+             name, (unsigned long long)e.ino);
1d442b
 
1d442b
     fuse_reply_entry(req, &e);
1d442b
     return;
1d442b
@@ -1074,10 +1061,8 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
1d442b
     pthread_mutex_unlock(&lo->mutex);
1d442b
     e.ino = inode->fuse_ino;
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n",
1d442b
-                 (unsigned long long)parent, name, (unsigned long long)e.ino);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n", (unsigned long long)parent,
1d442b
+             name, (unsigned long long)e.ino);
1d442b
 
1d442b
     fuse_reply_entry(req, &e);
1d442b
     return;
1d442b
@@ -1171,11 +1156,9 @@ static void lo_forget_one(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
1d442b
         return;
1d442b
     }
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "  forget %lli %lli -%lli\n",
1d442b
-                 (unsigned long long)ino, (unsigned long long)inode->refcount,
1d442b
-                 (unsigned long long)nlookup);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "  forget %lli %lli -%lli\n",
1d442b
+             (unsigned long long)ino, (unsigned long long)inode->refcount,
1d442b
+             (unsigned long long)nlookup);
1d442b
 
1d442b
     unref_inode(lo, inode, nlookup);
1d442b
 }
1d442b
@@ -1445,10 +1428,8 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
     int err;
1d442b
     struct lo_cred old = {};
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "lo_create(parent=%" PRIu64 ", name=%s)\n",
1d442b
-                 parent, name);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_create(parent=%" PRIu64 ", name=%s)\n", parent,
1d442b
+             name);
1d442b
 
1d442b
     if (!is_safe_path_component(name)) {
1d442b
         fuse_reply_err(req, EINVAL);
1d442b
@@ -1525,10 +1506,8 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
1d442b
     char buf[64];
1d442b
     struct lo_data *lo = lo_data(req);
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "lo_open(ino=%" PRIu64 ", flags=%d)\n", ino,
1d442b
-                 fi->flags);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_open(ino=%" PRIu64 ", flags=%d)\n", ino,
1d442b
+             fi->flags);
1d442b
 
1d442b
     /*
1d442b
      * With writeback cache, kernel may send read requests even
1d442b
@@ -1644,12 +1623,10 @@ static void lo_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t offset,
1d442b
 {
1d442b
     struct fuse_bufvec buf = FUSE_BUFVEC_INIT(size);
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG,
1d442b
-                 "lo_read(ino=%" PRIu64 ", size=%zd, "
1d442b
-                 "off=%lu)\n",
1d442b
-                 ino, size, (unsigned long)offset);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG,
1d442b
+             "lo_read(ino=%" PRIu64 ", size=%zd, "
1d442b
+             "off=%lu)\n",
1d442b
+             ino, size, (unsigned long)offset);
1d442b
 
1d442b
     buf.buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK;
1d442b
     buf.buf[0].fd = lo_fi_fd(req, fi);
1d442b
@@ -1671,11 +1648,9 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
1d442b
     out_buf.buf[0].fd = lo_fi_fd(req, fi);
1d442b
     out_buf.buf[0].pos = off;
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG,
1d442b
-                 "lo_write(ino=%" PRIu64 ", size=%zd, off=%lu)\n", ino,
1d442b
-                 out_buf.buf[0].size, (unsigned long)off);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG,
1d442b
+             "lo_write_buf(ino=%" PRIu64 ", size=%zd, off=%lu)\n", ino,
1d442b
+             out_buf.buf[0].size, (unsigned long)off);
1d442b
 
1d442b
     /*
1d442b
      * If kill_priv is set, drop CAP_FSETID which should lead to kernel
1d442b
@@ -1774,11 +1749,8 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
1d442b
         goto out;
1d442b
     }
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG,
1d442b
-                 "lo_getxattr(ino=%" PRIu64 ", name=%s size=%zd)\n", ino, name,
1d442b
-                 size);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_getxattr(ino=%" PRIu64 ", name=%s size=%zd)\n",
1d442b
+             ino, name, size);
1d442b
 
1d442b
     if (inode->is_symlink) {
1d442b
         /* Sorry, no race free way to getxattr on symlink. */
1d442b
@@ -1852,10 +1824,8 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
1d442b
         goto out;
1d442b
     }
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "lo_listxattr(ino=%" PRIu64 ", size=%zd)\n",
1d442b
-                 ino, size);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_listxattr(ino=%" PRIu64 ", size=%zd)\n", ino,
1d442b
+             size);
1d442b
 
1d442b
     if (inode->is_symlink) {
1d442b
         /* Sorry, no race free way to listxattr on symlink. */
1d442b
@@ -1929,11 +1899,8 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
1d442b
         goto out;
1d442b
     }
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG,
1d442b
-                 "lo_setxattr(ino=%" PRIu64 ", name=%s value=%s size=%zd)\n",
1d442b
-                 ino, name, value, size);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_setxattr(ino=%" PRIu64
1d442b
+             ", name=%s value=%s size=%zd)\n", ino, name, value, size);
1d442b
 
1d442b
     if (inode->is_symlink) {
1d442b
         /* Sorry, no race free way to setxattr on symlink. */
1d442b
@@ -1978,10 +1945,8 @@ static void lo_removexattr(fuse_req_t req, fuse_ino_t ino, const char *name)
1d442b
         goto out;
1d442b
     }
1d442b
 
1d442b
-    if (lo_debug(req)) {
1d442b
-        fuse_log(FUSE_LOG_DEBUG, "lo_removexattr(ino=%" PRIu64 ", name=%s)\n",
1d442b
-                 ino, name);
1d442b
-    }
1d442b
+    fuse_log(FUSE_LOG_DEBUG, "lo_removexattr(ino=%" PRIu64 ", name=%s)\n", ino,
1d442b
+             name);
1d442b
 
1d442b
     if (inode->is_symlink) {
1d442b
         /* Sorry, no race free way to setxattr on symlink. */
1d442b
@@ -2303,6 +2268,10 @@ static void setup_nofile_rlimit(void)
1d442b
 
1d442b
 static void log_func(enum fuse_log_level level, const char *fmt, va_list ap)
1d442b
 {
1d442b
+    if (current_log_level < level) {
1d442b
+        return;
1d442b
+    }
1d442b
+
1d442b
     if (use_syslog) {
1d442b
         int priority = LOG_ERR;
1d442b
         switch (level) {
1d442b
@@ -2401,8 +2370,19 @@ int main(int argc, char *argv[])
1d442b
         return 1;
1d442b
     }
1d442b
 
1d442b
+    /*
1d442b
+     * log_level is 0 if not configured via cmd options (0 is LOG_EMERG,
1d442b
+     * and we don't use this log level).
1d442b
+     */
1d442b
+    if (opts.log_level != 0) {
1d442b
+        current_log_level = opts.log_level;
1d442b
+    }
1d442b
     lo.debug = opts.debug;
1d442b
+    if (lo.debug) {
1d442b
+        current_log_level = FUSE_LOG_DEBUG;
1d442b
+    }
1d442b
     lo.root.refcount = 2;
1d442b
+
1d442b
     if (lo.source) {
1d442b
         struct stat stat;
1d442b
         int res;