Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07f48ad0 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Do not terminate AppFuse message loop when FUSE_FORGET.

Currently AppFuse tries to terminate its message loop when it receives
FUSE_FORGET. But kernel continues to dispatch messages after FUSE_FORGET
and it should not terminate AppFuse meesage loop.

Change-Id: I070a71c35a8d80bcaaf7603305d219e65be97bc9
Fixes: 28508169
parent e2be9f4a
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -120,44 +120,45 @@ public:
    AppFuse(JNIEnv* env, jobject self) :
        env_(env), self_(self), handle_counter_(0) {}

    bool handle_fuse_request(int fd, FuseRequest* req) {
    void handle_fuse_request(int fd, FuseRequest* req) {
        ALOGV("Request op=%d", req->header().opcode);
        switch (req->header().opcode) {
            // TODO: Handle more operations that are enough to provide seekable
            // FD.
            case FUSE_LOOKUP:
                invoke_handler(fd, req, &AppFuse::handle_fuse_lookup);
                return true;
                return;
            case FUSE_FORGET:
                // Return without replying.
                return;
            case FUSE_INIT:
                invoke_handler(fd, req, &AppFuse::handle_fuse_init);
                return true;
                return;
            case FUSE_GETATTR:
                invoke_handler(fd, req, &AppFuse::handle_fuse_getattr);
                return true;
            case FUSE_FORGET:
                return false;
                return;
            case FUSE_OPEN:
                invoke_handler(fd, req, &AppFuse::handle_fuse_open);
                return true;
                return;
            case FUSE_READ:
                invoke_handler(fd, req, &AppFuse::handle_fuse_read);
                return true;
                return;
            case FUSE_WRITE:
                invoke_handler(fd, req, &AppFuse::handle_fuse_write);
                return true;
                return;
            case FUSE_RELEASE:
                invoke_handler(fd, req, &AppFuse::handle_fuse_release);
                return true;
                return;
            case FUSE_FLUSH:
                invoke_handler(fd, req, &AppFuse::handle_fuse_flush);
                return true;
                return;
            default: {
                ALOGV("NOTIMPL op=%d uniq=%" PRIx64 " nid=%" PRIx64 "\n",
                      req->header().opcode,
                      req->header().unique,
                      req->header().nodeid);
                fuse_reply(fd, req->header().unique, -ENOSYS, NULL, 0);
                return true;
                return;
            }
        }
    }
@@ -445,8 +446,7 @@ private:
    }
};

jboolean com_android_mtp_AppFuse_start_app_fuse_loop(
        JNIEnv* env, jobject self, jint jfd) {
void com_android_mtp_AppFuse_start_app_fuse_loop(JNIEnv* env, jobject self, jint jfd) {
    ScopedFd fd(static_cast<int>(jfd));
    AppFuse appfuse(env, self);

@@ -458,8 +458,8 @@ jboolean com_android_mtp_AppFuse_start_app_fuse_loop(
                read(fd, request.buffer, sizeof(request.buffer)));
        if (result < 0) {
            if (errno == ENODEV) {
                ALOGE("Someone stole our marbles!\n");
                return JNI_FALSE;
                ALOGV("AppFuse was unmounted.\n");
                return;
            }
            ALOGE("Failed to read bytes from FD: errno=%d\n", errno);
            continue;
@@ -477,16 +477,14 @@ jboolean com_android_mtp_AppFuse_start_app_fuse_loop(
            continue;
        }

        if (!appfuse.handle_fuse_request(fd, &request)) {
            return JNI_TRUE;
        }
        appfuse.handle_fuse_request(fd, &request);
    }
}

static const JNINativeMethod gMethods[] = {
    {
        "native_start_app_fuse_loop",
        "(I)Z",
        "(I)V",
        (void *) com_android_mtp_AppFuse_start_app_fuse_loop
    }
};
+2 −2
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ public class AppFuse {
    void close() {
        try {
            // Remote side of ParcelFileDescriptor is tracking the close of mDeviceFd, and unmount
            // the corresponding fuse file system. The mMessageThread will receive FUSE_FORGET, and
            // the corresponding fuse file system. The mMessageThread will receive ENODEV, and
            // then terminate itself.
            mDeviceFd.close();
            mMessageThread.join();
@@ -236,7 +236,7 @@ public class AppFuse {
        }
    }

    private native boolean native_start_app_fuse_loop(int fd);
    private native void native_start_app_fuse_loop(int fd);

    private class AppFuseMessageThread extends Thread {
        /**