forked from acozzette/BUSE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buseOperations.cpp
70 lines (59 loc) · 2.2 KB
/
buseOperations.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* buseOperations.cpp
*
* Created on: Jan 25, 2015
* Author: andras
*/
#include "buseOperations.h"
#include <chrono>
#include <iostream>
using namespace std;
namespace buse {
buseOperations::buseOperations() { this->size = 0; }
buseOperations::buseOperations(uint64_t size) { this->size = size; }
buseOperations::~buseOperations() {
DEBUGPRINTLN("Destroying buse object.");
while(!disks.empty()) { close(disks.back().getFD()); disks.pop_back(); }
}
int buseOperations::read(void *buf, size_t len, off64_t offset) {
UNUSED(buf); UNUSED(len); UNUSED(offset);
DEBUGPRINTLN("R - " << offset << ", " << len);
return handleTX(buf,len, offset,::commonIncludesRead);
}
int buseOperations::write(const void *buf, size_t len, off64_t offset) {
UNUSED(buf); UNUSED(len); UNUSED(offset);
DEBUGPRINTLN("W - " << offset << ", " << len);
return handleTX((void*)buf,len, offset,::commonIncludesWrite);
}
int buseOperations::handleTX(void *buf, size_t len, off64_t offset, ssize_t (*func)(int, void *, size_t)) {
UNUSED(buf); UNUSED(len); UNUSED(offset); UNUSED(func);
DEBUGPRINTLN("H - " << offset << ", " << len);
return 0;
}
void buseOperations::disc() { DEBUGPRINTLN("Received a disconnect request."); }
int buseOperations::flush() {
DEBUGPRINTLN("Received a flush request.");
for(uint i = 0; i < this->disks.size(); i++) ::syncfs(disks[i].getFD());
return 0;
}
int buseOperations::trim(uint64_t from, uint32_t len) {
UNUSED(from); UNUSED(len);
DEBUGPRINTLN("T - " << from << ", " << len);
return 0;
}
uint8_t buseOperations::getNumAsyncIdle() {
uint8_t numDisks = 0;
for(uint i = 0; i < disks.size(); i++) { numDisks += (uint8_t)(disks[i].aio_error()!=EINPROGRESS); }
return numDisks;
}
uint8_t buseOperations::getFastestIdleReadDisk() {
uint8_t cdID = 0;
for(uint8_t i = 0; i < disks.size(); i++) { if((disks[i].aio_error()!=EINPROGRESS) && (disks[cdID].getReadSpeed() > disks[i].getReadSpeed())) cdID = i; }
return cdID;
}
uint8_t buseOperations::getFastestIdleWriteDisk() {
uint8_t cdID = 0;
for(uint8_t i = 0; i < disks.size(); i++) { if((disks[i].aio_error()!=EINPROGRESS) && (disks[cdID].getWriteSpeed() > disks[i].getWriteSpeed())) cdID = i; }
return cdID;
}
}