summaryrefslogtreecommitdiffstats
path: root/sdcard
diff options
context:
space:
mode:
authorJorge Lucangeli Obes <jorgelo@google.com>2016-07-20 15:19:44 -0400
committerJorge Lucangeli Obes <jorgelo@google.com>2016-07-21 17:11:47 -0400
commit714ec9d1de9a8687be9203dee9c1f9cb13a9d73d (patch)
treeaa169aa73e75622ed0bd7232fc687bd3bb9cc3ea /sdcard
parentc15ab6e2c66697abadd9478b5e5e19c7c11f83ec (diff)
downloadcore-714ec9d1de9a8687be9203dee9c1f9cb13a9d73d.tar.gz
core-714ec9d1de9a8687be9203dee9c1f9cb13a9d73d.tar.bz2
core-714ec9d1de9a8687be9203dee9c1f9cb13a9d73d.zip
sdcard: Fix compilation with FUSE_TRACE == 1.
"PRI{u,x}64" was not compiling on C++ because of macro expansions. Implement DLOG the same way DCHECK is implemented in <android-base/logging.h>, and mechanically replace the problematic lines with C++ logging. Remaining TRACE() lines will be replaced in a follow-up CL. Bug: 30222003 Change-Id: I377a91722eb4c035093fc96b79438c4f638b9a45
Diffstat (limited to 'sdcard')
-rw-r--r--sdcard/fuse.cpp78
-rw-r--r--sdcard/fuse.h10
2 files changed, 52 insertions, 36 deletions
diff --git a/sdcard/fuse.cpp b/sdcard/fuse.cpp
index 9b1b19065..03ca4dc34 100644
--- a/sdcard/fuse.cpp
+++ b/sdcard/fuse.cpp
@@ -18,6 +18,8 @@
#include "fuse.h"
+#include <android-base/logging.h>
+
#define FUSE_UNKNOWN_INO 0xffffffff
/* Pseudo-error constant used to indicate that no fuse status is needed
@@ -573,8 +575,8 @@ static int handle_lookup(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] LOOKUP %s @ %" PRIx64 " (%s)\n", handler->token, name, hdr->nodeid,
- parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] LOOKUP " << name << " @ " << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !(actual_name = find_file_within(parent_path, name,
@@ -595,8 +597,9 @@ static int handle_forget(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_by_id_locked(fuse, hdr->nodeid);
- TRACE("[%d] FORGET #%" PRIu64 " @ %" PRIx64 " (%s)\n", handler->token, req->nlookup,
- hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] FORGET #" << req->nlookup
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (node ? node->name : "?") << ")";
if (node) {
__u64 n = req->nlookup;
while (n) {
@@ -616,8 +619,9 @@ static int handle_getattr(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] GETATTR flags=%x fh=%" PRIx64 " @ %" PRIx64 " (%s)\n", handler->token,
- req->getattr_flags, req->fh, hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] GETATTR flags=" << req->getattr_flags
+ << " fh=" << std::hex << req->fh << " @ " << std::hex << hdr->nodeid
+ << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -639,8 +643,9 @@ static int handle_setattr(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] SETATTR fh=%" PRIx64 " valid=%x @ %" PRIx64 " (%s)\n", handler->token,
- req->fh, req->valid, hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] SETATTR fh=" << std::hex << req->fh
+ << " valid=" << std::hex << req->valid << " @ " << std::hex << hdr->nodeid
+ << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -704,8 +709,9 @@ static int handle_mknod(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] MKNOD %s 0%o @ %" PRIx64 " (%s)\n", handler->token,
- name, req->mode, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] MKNOD " << name << " 0" << std::oct << req->mode
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !(actual_name = find_file_within(parent_path, name,
@@ -733,8 +739,9 @@ static int handle_mkdir(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] MKDIR %s 0%o @ %" PRIx64 " (%s)\n", handler->token,
- name, req->mode, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] MKDIR " << name << " 0" << std::oct << req->mode
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !(actual_name = find_file_within(parent_path, name,
@@ -781,8 +788,8 @@ static int handle_unlink(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] UNLINK %s @ %" PRIx64 " (%s)\n", handler->token,
- name, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] UNLINK " << name << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !find_file_within(parent_path, name,
@@ -803,8 +810,9 @@ static int handle_unlink(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_unlock(&fuse->global->lock);
if (parent_node && child_node) {
/* Tell all other views that node is gone */
- TRACE("[%d] fuse_notify_delete parent=%" PRIx64 ", child=%" PRIx64 ", name=%s\n",
- handler->token, (uint64_t) parent_node->nid, (uint64_t) child_node->nid, name);
+ DLOG(INFO) << "[" << handler->token << "] fuse_notify_delete"
+ << " parent=" << std::hex << parent_node->nid
+ << ", child=" << std::hex << child_node->nid << ", name=" << name;
if (fuse != fuse->global->fuse_default) {
fuse_notify_delete(fuse->global->fuse_default, parent_node->nid, child_node->nid, name);
}
@@ -829,8 +837,8 @@ static int handle_rmdir(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] RMDIR %s @ %" PRIx64 " (%s)\n", handler->token,
- name, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] UNLINK " << name << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !find_file_within(parent_path, name,
@@ -851,8 +859,9 @@ static int handle_rmdir(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_unlock(&fuse->global->lock);
if (parent_node && child_node) {
/* Tell all other views that node is gone */
- TRACE("[%d] fuse_notify_delete parent=%" PRIx64 ", child=%" PRIx64 ", name=%s\n",
- handler->token, (uint64_t) parent_node->nid, (uint64_t) child_node->nid, name);
+ DLOG(INFO) << "[" << handler->token << "] fuse_notify_delete"
+ << " parent=" << std::hex << parent_node->nid
+ << ", child=" << std::hex << child_node->nid << ", name=" << name;
if (fuse != fuse->global->fuse_default) {
fuse_notify_delete(fuse->global->fuse_default, parent_node->nid, child_node->nid, name);
}
@@ -886,10 +895,11 @@ static int handle_rename(struct fuse* fuse, struct fuse_handler* handler,
old_parent_path, sizeof(old_parent_path));
new_parent_node = lookup_node_and_path_by_id_locked(fuse, req->newdir,
new_parent_path, sizeof(new_parent_path));
- TRACE("[%d] RENAME %s->%s @ %" PRIx64 " (%s) -> %" PRIx64 " (%s)\n", handler->token,
- old_name, new_name,
- hdr->nodeid, old_parent_node ? old_parent_node->name : "?",
- req->newdir, new_parent_node ? new_parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] RENAME " << old_name << "->" << new_name
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (old_parent_node ? old_parent_node->name : "?") << ") -> "
+ << std::hex << req->newdir
+ << " (" << (new_parent_node ? new_parent_node->name : "?") << ")";
if (!old_parent_node || !new_parent_node) {
res = -ENOENT;
goto lookup_error;
@@ -970,8 +980,8 @@ static int handle_open(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] OPEN 0%o @ %" PRIx64 " (%s)\n", handler->token,
- req->flags, hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] OPEN 0" << std::oct << req->flags
+ << " @ " << std::hex << hdr->nodeid << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -1018,8 +1028,8 @@ static int handle_read(struct fuse* fuse, struct fuse_handler* handler,
* overlaps the request buffer and will clobber data in the request. This
* saves us 128KB per request handler thread at the cost of this scary comment. */
- TRACE("[%d] READ %p(%d) %u@%" PRIu64 "\n", handler->token,
- h, h->fd, size, (uint64_t) offset);
+ DLOG(INFO) << "[" << handler->token << "] READ " << std::hex << h << "(" << h->fd << ") "
+ << size << "@" << offset;
if (size > MAX_READ) {
return -EINVAL;
}
@@ -1045,8 +1055,8 @@ static int handle_write(struct fuse* fuse, struct fuse_handler* handler,
buffer = (const __u8*) aligned_buffer;
}
- TRACE("[%d] WRITE %p(%d) %u@%" PRIu64 "\n", handler->token,
- h, h->fd, req->size, req->offset);
+ DLOG(INFO) << "[" << handler->token << "] WRITE " << std::hex << h << "(" << h->fd << ") "
+ << req->size << "@" << req->offset;
res = pwrite64(h->fd, buffer, req->size, req->offset);
if (res < 0) {
return -errno;
@@ -1141,8 +1151,8 @@ static int handle_opendir(struct fuse* fuse, struct fuse_handler* handler,
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] OPENDIR @ %" PRIx64 " (%s)\n", handler->token,
- hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] OPENDIR @ " << std::hex << hdr->nodeid
+ << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -1379,8 +1389,8 @@ static int handle_fuse_request(struct fuse *fuse, struct fuse_handler* handler,
}
default: {
- TRACE("[%d] NOTIMPL op=%d uniq=%" PRIx64 " nid=%" PRIx64 "\n",
- handler->token, hdr->opcode, hdr->unique, hdr->nodeid);
+ DLOG(INFO) << "[" << handler->token << "] NOTIMPL op=" << hdr->opcode
+ << "uniq=" << std::hex << hdr->unique << "nid=" << std::hex << hdr->nodeid;
return -ENOSYS;
}
}
diff --git a/sdcard/fuse.h b/sdcard/fuse.h
index 634fbf191..9dafa79ea 100644
--- a/sdcard/fuse.h
+++ b/sdcard/fuse.h
@@ -33,6 +33,7 @@
#include <map>
#include <string>
+#include <android-base/logging.h>
#include <cutils/fs.h>
#include <cutils/log.h>
#include <cutils/multiuser.h>
@@ -40,15 +41,20 @@
#include <private/android_filesystem_config.h>
-// TODO(b/30222003): Fix compilation with FUSE_TRACE == 1.
#define FUSE_TRACE 0
#if FUSE_TRACE
#define TRACE(x...) ALOGD(x)
-#else
+static constexpr bool kEnableDLog = true;
+#else // FUSE_TRACE == 0
#define TRACE(x...) do {} while (0)
+static constexpr bool kEnableDLog = false;
#endif
+// Use same strategy as DCHECK().
+#define DLOG(x) \
+ if (kEnableDLog) LOG(x)
+
#define ERROR(x...) ALOGE(x)
/* Maximum number of bytes to write in one request. */