vold: Clean up asec command response and add support for 'StorageBusy'

Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
San Mehat 2010-02-18 11:40:49 -08:00
parent 4ba8948dc1
commit 8f2875b297
4 changed files with 61 additions and 51 deletions

View file

@ -24,7 +24,8 @@ LOCAL_SRC_FILES:= \
geom_mbr_enc.c \
Fat.cpp \
Loop.cpp \
Devmapper.cpp
Devmapper.cpp \
ResponseCode.cpp
LOCAL_MODULE:= vold

View file

@ -88,21 +88,8 @@ int CommandListener::VolumeCmd::runCommand(SocketClient *cli,
if (!rc) {
cli->sendMsg(ResponseCode::CommandOkay, "volume operation succeeded", false);
} else {
/*
* Failed
*/
if (errno == ENODEV) {
rc = ResponseCode::OpFailedNoMedia;
} else if (errno == ENODATA) {
rc = ResponseCode::OpFailedMediaBlank;
} else if (errno == EIO) {
rc = ResponseCode::OpFailedMediaCorrupt;
} else if (errno == EBUSY) {
rc = ResponseCode::OpFailedVolBusy;
} else {
LOGW("Returning OperationFailed - no handler for errno %d", errno);
rc = ResponseCode::OperationFailed;
}
int erno = errno;
rc = ResponseCode::convertFromErrno();
cli->sendMsg(rc, "volume operation failed", true);
}
@ -223,7 +210,6 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
}
}
closedir(d);
cli->sendMsg(ResponseCode::CommandOkay, "ASEC listing complete", false);
} else if (!strcmp(argv[1], "create")) {
if (argc != 7) {
cli->sendMsg(ResponseCode::CommandSyntaxError,
@ -232,21 +218,13 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
}
unsigned int numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512;
if (vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]))) {
cli->sendMsg(ResponseCode::OperationFailed, "Container creation failed", true);
} else {
cli->sendMsg(ResponseCode::CommandOkay, "Container created", false);
}
rc = vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]));
} else if (!strcmp(argv[1], "finalize")) {
if (argc != 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec finalize <container-id>", false);
return 0;
}
if (vm->finalizeAsec(argv[2])) {
cli->sendMsg(ResponseCode::OperationFailed, "Container finalize failed", true);
} else {
cli->sendMsg(ResponseCode::CommandOkay, "Container finalized", false);
}
rc = vm->finalizeAsec(argv[2]);
} else if (!strcmp(argv[1], "destroy")) {
if (argc < 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec destroy <container-id> [force]", false);
@ -256,25 +234,14 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
if (argc > 3 && !strcmp(argv[3], "force")) {
force = true;
}
if (vm->destroyAsec(argv[2], force)) {
cli->sendMsg(ResponseCode::OperationFailed, "Container destroy failed", true);
} else {
cli->sendMsg(ResponseCode::CommandOkay, "Container destroyed", false);
}
rc = vm->destroyAsec(argv[2], force);
} else if (!strcmp(argv[1], "mount")) {
if (argc != 5) {
cli->sendMsg(ResponseCode::CommandSyntaxError,
"Usage: asec mount <namespace-id> <key> <ownerUid>", false);
return 0;
}
int rc = vm->mountAsec(argv[2], argv[3], atoi(argv[4]));
if (rc < 0) {
cli->sendMsg(ResponseCode::OperationFailed, "Mount failed", true);
} else {
cli->sendMsg(ResponseCode::CommandOkay, "Mount succeeded", false);
}
rc = vm->mountAsec(argv[2], argv[3], atoi(argv[4]));
} else if (!strcmp(argv[1], "unmount")) {
if (argc < 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec unmount <container-id> [force]", false);
@ -284,22 +251,14 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
if (argc > 3 && !strcmp(argv[3], "force")) {
force = true;
}
if (vm->unmountAsec(argv[2], force)) {
cli->sendMsg(ResponseCode::OperationFailed, "Container unmount failed", true);
} else {
cli->sendMsg(ResponseCode::CommandOkay, "Container unmounted", false);
}
rc = vm->unmountAsec(argv[2], force);
} else if (!strcmp(argv[1], "rename")) {
if (argc != 4) {
cli->sendMsg(ResponseCode::CommandSyntaxError,
"Usage: asec rename <old_id> <new_id>", false);
return 0;
}
if (vm->renameAsec(argv[2], argv[3])) {
cli->sendMsg(ResponseCode::OperationFailed, "Container rename failed", true);
} else {
cli->sendMsg(ResponseCode::CommandOkay, "Container renamed", false);
}
rc = vm->renameAsec(argv[2], argv[3]);
} else if (!strcmp(argv[1], "path")) {
if (argc != 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec path <container-id>", false);
@ -312,9 +271,17 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
} else {
cli->sendMsg(ResponseCode::AsecPathResult, path, false);
}
return 0;
} else {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown asec cmd", false);
}
if (!rc) {
cli->sendMsg(ResponseCode::CommandOkay, "asec operation succeeded", false);
} else {
rc = ResponseCode::convertFromErrno();
cli->sendMsg(rc, "asec operation failed", true);
}
return 0;
}

40
ResponseCode.cpp Normal file
View file

@ -0,0 +1,40 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define LOG_TAG "Vold"
#include <cutils/log.h>
#include "ResponseCode.h"
int ResponseCode::convertFromErrno() {
if (errno == ENODEV) {
return(ResponseCode::OpFailedNoMedia);
} else if (errno == ENODATA) {
return(ResponseCode::OpFailedMediaBlank);
} else if (errno == EIO) {
return(ResponseCode::OpFailedMediaCorrupt);
} else if (errno == EBUSY) {
return(ResponseCode::OpFailedStorageBusy);
}
LOGW("Returning OperationFailed - no handler for errno %d", errno);
return(ResponseCode::OperationFailed);
}

View file

@ -40,7 +40,7 @@ public:
static const int OpFailedMediaBlank = 402;
static const int OpFailedMediaCorrupt = 403;
static const int OpFailedVolNotMounted = 404;
static const int OpFailedVolBusy = 405;
static const int OpFailedStorageBusy = 405;
// 500 series - The command was not accepted and the requested
// action did not take place.
@ -59,5 +59,7 @@ public:
static const int VolumeDiskInserted = 630;
static const int VolumeDiskRemoved = 631;
static const int VolumeBadRemoval = 632;
static int convertFromErrno();
};
#endif