Remove the FD parameter from FuseDataProvider ctor.
This leaves the FD implementation details to subclasses. In particular, it allows minadbd to do additional works with the FD after sideloading. Bug: 128415917 Test: atest recovery_component_test Test: atest minadbd_test Test: Sideload package on taimen. Change-Id: I106bbaad05201227bbc5fe28890bbbb06fdcb67e
This commit is contained in:
@@ -25,8 +25,8 @@
|
|||||||
// This is the base class to read data from source and provide the data to FUSE.
|
// This is the base class to read data from source and provide the data to FUSE.
|
||||||
class FuseDataProvider {
|
class FuseDataProvider {
|
||||||
public:
|
public:
|
||||||
FuseDataProvider(android::base::unique_fd&& fd, uint64_t file_size, uint32_t block_size)
|
FuseDataProvider(uint64_t file_size, uint32_t block_size)
|
||||||
: fd_(std::move(fd)), file_size_(file_size), fuse_block_size_(block_size) {}
|
: file_size_(file_size), fuse_block_size_(block_size) {}
|
||||||
|
|
||||||
virtual ~FuseDataProvider() = default;
|
virtual ~FuseDataProvider() = default;
|
||||||
|
|
||||||
@@ -37,21 +37,15 @@ class FuseDataProvider {
|
|||||||
return fuse_block_size_;
|
return fuse_block_size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Valid() const {
|
|
||||||
return fd_ != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads |fetch_size| bytes data starting from |start_block|. Puts the result in |buffer|.
|
// Reads |fetch_size| bytes data starting from |start_block|. Puts the result in |buffer|.
|
||||||
virtual bool ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size,
|
virtual bool ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size,
|
||||||
uint32_t start_block) const = 0;
|
uint32_t start_block) const = 0;
|
||||||
|
|
||||||
virtual void Close() = 0;
|
virtual void Close() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FuseDataProvider() = default;
|
FuseDataProvider() = default;
|
||||||
|
|
||||||
// The underlying source to read data from.
|
|
||||||
android::base::unique_fd fd_;
|
|
||||||
// Size in bytes of the file to read.
|
// Size in bytes of the file to read.
|
||||||
uint64_t file_size_ = 0;
|
uint64_t file_size_ = 0;
|
||||||
// Block size passed to the fuse, this is different from the block size of the block device.
|
// Block size passed to the fuse, this is different from the block size of the block device.
|
||||||
@@ -61,13 +55,18 @@ class FuseDataProvider {
|
|||||||
// This class reads data from a file.
|
// This class reads data from a file.
|
||||||
class FuseFileDataProvider : public FuseDataProvider {
|
class FuseFileDataProvider : public FuseDataProvider {
|
||||||
public:
|
public:
|
||||||
FuseFileDataProvider(android::base::unique_fd&& fd, uint64_t file_size, uint32_t block_size)
|
|
||||||
: FuseDataProvider(std::move(fd), file_size, block_size) {}
|
|
||||||
|
|
||||||
FuseFileDataProvider(const std::string& path, uint32_t block_size);
|
FuseFileDataProvider(const std::string& path, uint32_t block_size);
|
||||||
|
|
||||||
bool ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size,
|
bool ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size,
|
||||||
uint32_t start_block) const override;
|
uint32_t start_block) const override;
|
||||||
|
|
||||||
|
bool Valid() const {
|
||||||
|
return fd_ != -1;
|
||||||
|
}
|
||||||
|
|
||||||
void Close() override;
|
void Close() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// The underlying source to read data from.
|
||||||
|
android::base::unique_fd fd_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,25 +14,24 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __FUSE_ADB_PROVIDER_H
|
#pragma once
|
||||||
#define __FUSE_ADB_PROVIDER_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "android-base/unique_fd.h"
|
|
||||||
|
|
||||||
#include "fuse_provider.h"
|
#include "fuse_provider.h"
|
||||||
|
|
||||||
// This class reads data from adb server.
|
// This class reads data from adb server.
|
||||||
class FuseAdbDataProvider : public FuseDataProvider {
|
class FuseAdbDataProvider : public FuseDataProvider {
|
||||||
public:
|
public:
|
||||||
FuseAdbDataProvider(android::base::unique_fd&& fd, uint64_t file_size, uint32_t block_size)
|
FuseAdbDataProvider(int fd, uint64_t file_size, uint32_t block_size)
|
||||||
: FuseDataProvider(std::move(fd), file_size, block_size) {}
|
: FuseDataProvider(file_size, block_size), fd_(fd) {}
|
||||||
|
|
||||||
bool ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size,
|
bool ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size,
|
||||||
uint32_t start_block) const override;
|
uint32_t start_block) const override;
|
||||||
|
|
||||||
void Close() override;
|
void Close() override;
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
private:
|
||||||
|
// The underlying source to read data from (i.e. the one that talks to the host).
|
||||||
|
int fd_;
|
||||||
|
};
|
||||||
|
|||||||
@@ -96,8 +96,7 @@ static void sideload_host_service(unique_fd sfd, const std::string& args) {
|
|||||||
exit(kMinadbdSocketIOError);
|
exit(kMinadbdSocketIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto adb_data_reader =
|
auto adb_data_reader = std::make_unique<FuseAdbDataProvider>(sfd, file_size, block_size);
|
||||||
std::make_unique<FuseAdbDataProvider>(std::move(sfd), file_size, block_size);
|
|
||||||
if (int result = run_fuse_sideload(std::move(adb_data_reader)); result != 0) {
|
if (int result = run_fuse_sideload(std::move(adb_data_reader)); result != 0) {
|
||||||
LOG(ERROR) << "Failed to start fuse";
|
LOG(ERROR) << "Failed to start fuse";
|
||||||
exit(kMinadbdFuseStartError);
|
exit(kMinadbdFuseStartError);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <android-base/unique_fd.h>
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "fuse_provider.h"
|
#include "fuse_provider.h"
|
||||||
@@ -32,17 +31,26 @@ TEST(SideloadTest, fuse_device) {
|
|||||||
ASSERT_EQ(0, access("/dev/fuse", R_OK | W_OK));
|
ASSERT_EQ(0, access("/dev/fuse", R_OK | W_OK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FuseTestDataProvider : public FuseDataProvider {
|
||||||
|
public:
|
||||||
|
FuseTestDataProvider(uint64_t file_size, uint32_t block_size)
|
||||||
|
: FuseDataProvider(file_size, block_size) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool ReadBlockAlignedData(uint8_t*, uint32_t, uint32_t) const override {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TEST(SideloadTest, run_fuse_sideload_wrong_parameters) {
|
TEST(SideloadTest, run_fuse_sideload_wrong_parameters) {
|
||||||
auto provider_small_block =
|
auto provider_small_block = std::make_unique<FuseTestDataProvider>(4096, 4095);
|
||||||
std::make_unique<FuseFileDataProvider>(android::base::unique_fd(), 4096, 4095);
|
|
||||||
ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_small_block)));
|
ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_small_block)));
|
||||||
|
|
||||||
auto provider_large_block =
|
auto provider_large_block = std::make_unique<FuseTestDataProvider>(4096, (1 << 22) + 1);
|
||||||
std::make_unique<FuseFileDataProvider>(android::base::unique_fd(), 4096, (1 << 22) + 1);
|
|
||||||
ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_large_block)));
|
ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_large_block)));
|
||||||
|
|
||||||
auto provider_too_many_blocks = std::make_unique<FuseFileDataProvider>(
|
auto provider_too_many_blocks =
|
||||||
android::base::unique_fd(), ((1 << 18) + 1) * 4096, 4096);
|
std::make_unique<FuseTestDataProvider>(((1 << 18) + 1) * 4096, 4096);
|
||||||
ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_too_many_blocks)));
|
ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_too_many_blocks)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user