vold: Increase max supported loop devices to 255

Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
San Mehat 2010-01-09 12:24:05 -08:00
parent 8d934caeae
commit 8da6bcb006
3 changed files with 25 additions and 33 deletions

View file

@ -20,6 +20,9 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#define LOG_TAG "Vold" #define LOG_TAG "Vold"
#include <cutils/log.h> #include <cutils/log.h>
@ -69,29 +72,41 @@ int Loop::lookupActive(const char *loopFile, char *buffer, size_t len) {
return 0; return 0;
} }
int Loop::getNextAvailable(char *buffer, size_t len) { int Loop::create(const char *loopFile, char *loopDeviceBuffer, size_t len) {
int i; int i;
int fd; int fd;
char filename[256]; char filename[256];
memset(buffer, 0, len);
for (i = 0; i < LOOP_MAX; i++) { for (i = 0; i < LOOP_MAX; i++) {
struct loop_info li; struct loop_info li;
int rc; int rc;
sprintf(filename, "/dev/block/loop%d", i); sprintf(filename, "/dev/block/loop%d", i);
/*
* The kernel starts us off with 8 loop nodes, but more
* are created on-demand if needed.
*/
mode_t mode = 0660 | S_IFBLK;
dev_t dev = (7 << 8) | i;
if (mknod(filename, mode, dev) < 0) {
if (errno != EEXIST) {
LOGE("Error creating loop device node (%s)", strerror(errno));
return -1;
}
}
if ((fd = open(filename, O_RDWR)) < 0) { if ((fd = open(filename, O_RDWR)) < 0) {
LOGE("Unable to open %s (%s)", filename, strerror(errno)); LOGE("Unable to open %s (%s)", filename, strerror(errno));
return -1; return -1;
} }
rc = ioctl(fd, LOOP_GET_STATUS, &li); rc = ioctl(fd, LOOP_GET_STATUS, &li);
close(fd);
if (rc < 0 && errno == ENXIO) if (rc < 0 && errno == ENXIO)
break; break;
close(fd);
if (rc < 0) { if (rc < 0) {
LOGE("Unable to get loop status for %s (%s)", filename, LOGE("Unable to get loop status for %s (%s)", filename,
strerror(errno)); strerror(errno));
@ -104,22 +119,11 @@ int Loop::getNextAvailable(char *buffer, size_t len) {
errno = ENOSPC; errno = ENOSPC;
return -1; return -1;
} }
strncpy(buffer, filename, len -1);
return 0;
}
int Loop::create(const char *loopDevice, const char *loopFile) { strncpy(loopDeviceBuffer, filename, len -1);
int fd;
int file_fd; int file_fd;
LOGD("Creating loop for file '%s' into loop device '%s'", loopFile,
loopDevice);
if ((fd = open(loopDevice, O_RDWR)) < 0) {
LOGE("Unable to open loop device %s (%s)", loopDevice,
strerror(errno));
return -1;
}
if ((file_fd = open(loopFile, O_RDWR)) < 0) { if ((file_fd = open(loopFile, O_RDWR)) < 0) {
LOGE("Unable to open %s (%s)", loopFile, strerror(errno)); LOGE("Unable to open %s (%s)", loopFile, strerror(errno));
close(fd); close(fd);

6
Loop.h
View file

@ -22,12 +22,10 @@
class Loop { class Loop {
public: public:
static const int LOOP_MAX = 8; static const int LOOP_MAX = 255;
public: public:
static int getNextAvailable(char *buffer, size_t len);
static int lookupActive(const char *loopFile, char *buffer, size_t len); static int lookupActive(const char *loopFile, char *buffer, size_t len);
static int create(const char *loopFile, char *loopDeviceBuffer, size_t len);
static int create(const char *loopDevice, const char *loopFile);
static int destroyByDevice(const char *loopDevice); static int destroyByDevice(const char *loopDevice);
static int destroyByFile(const char *loopFile); static int destroyByFile(const char *loopFile);
static int createImageFile(const char *file, size_t sizeMb); static int createImageFile(const char *file, size_t sizeMb);

View file

@ -198,12 +198,7 @@ int VolumeManager::createAsec(const char *id, int sizeMb,
} }
char loopDevice[255]; char loopDevice[255];
if (Loop::getNextAvailable(loopDevice, sizeof(loopDevice))) { if (Loop::create(asecFileName, loopDevice, sizeof(loopDevice))) {
unlink(asecFileName);
return -1;
}
if (Loop::create(loopDevice, asecFileName)) {
LOGE("ASEC loop device creation failed (%s)", strerror(errno)); LOGE("ASEC loop device creation failed (%s)", strerror(errno));
unlink(asecFileName); unlink(asecFileName);
return -1; return -1;
@ -327,12 +322,7 @@ int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) {
char loopDevice[255]; char loopDevice[255];
if (Loop::lookupActive(asecFileName, loopDevice, sizeof(loopDevice))) { if (Loop::lookupActive(asecFileName, loopDevice, sizeof(loopDevice))) {
if (Loop::getNextAvailable(loopDevice, sizeof(loopDevice))) { if (Loop::create(asecFileName, loopDevice, sizeof(loopDevice))) {
LOGE("Unable to find loop device for ASEC mount");
return -1;
}
if (Loop::create(loopDevice, asecFileName)) {
LOGE("ASEC loop device creation failed (%s)", strerror(errno)); LOGE("ASEC loop device creation failed (%s)", strerror(errno));
return -1; return -1;
} }