-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpdetail_form.cpp
executable file
·153 lines (137 loc) · 4.63 KB
/
cpdetail_form.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "cpdetail_form.h"
#include "ui_cpdetail_form.h"
#include <QFile>
#include <QTextStream>
#include <QProcess>
#include <QDebug>
#include <QFileDialog>
#include <QErrorMessage>
#include <QMessageBox>
cpDetail_form::cpDetail_form(QWidget *parent) :
QDialog(parent),
ui(new Ui::cpDetail_form)
{
ui->setupUi(this);
}
cpDetail_form::cpDetail_form(MainWindow *retForm, int cnt, QString path):
ui(new Ui::cpDetail_form)
{
this->retForm = retForm;
ui->setupUi(this);
/* binding */
hash["checkpoint_ver"] = ui->verNum_text;
hash["alloc_block_count"] = ui->allocBlk_text;
hash["valid_block_count"] = ui->validBlk_text;
//Version 1
/*
hash["free_segment_count"] = ui->freeSeg_text;
hash["cur_node_segno"] = ui->nodeSegNo_text;
hash["cur_node_blkoff"] = ui->nodeSegOfs_text;
hash["cur_data_segno"] = ui->dataSegNo_text;
hash["cur_data_blkoff"] = ui->dataSegOfs_text;
*/
//Version 2
hash["current segment (0)"] = ui->freeSeg_text;
hash["current segment (1)"] = ui->nodeSegNo_text;
hash["current segment (2)"] = ui->nodeSegOfs_text;
hash["current segment (3)"] = ui->dataSegNo_text;
hash["current segment (4)"] = ui->dataSegOfs_text;
hash["valid_inode_count"] = ui->validInode_text;
hash["valid_node_count"] = ui->validNode_text;
hash["wall_time"] = ui->wallTime_text;
verNum=cnt;
dirName = path;
errMsg = new QErrorMessage(this);
QFile cp_file("/sys/kernel/debug/hmfs/"+path+"/info");
if(!cp_file.open(QIODevice::ReadWrite)){
/* TODO: error prompt */
return;
}
QTextStream out(&cp_file);
out << "cp "<< verNum <<endl;
QTextStream in(&cp_file);
QString line = in.readLine();
while(!in.atEnd()) {
if(!line.length()) {
line = in.readLine();
continue;
}
QStringList list = line.split(":");
QLineEdit *t=hash.value(list[0]);
if(t != NULL){
t->setText(list[1].trimmed());
}
line = in.readLine();
}
}
cpDetail_form::~cpDetail_form()
{
delete ui;
free(errMsg);
}
void cpDetail_form::on_cpDetail_form_finished(int result)
{
this->retForm->show();
this->retForm->refresh();
this->hash.clear();
}
void cpDetail_form::on_btnMount_clicked()
{
QString mountPath = QFileDialog::getExistingDirectory(this,"Choose the mounting point",
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
QProcess umount;
umount.start("umount", QStringList() << mountPath);
if(!umount.waitForStarted()){
errMsg->showMessage("Start umount failed");
return;
}
umount.waitForFinished();
QString output = QString(umount.readAllStandardError());
//qDebug() << "Str: " << output;
if(output != "") {
errMsg->showMessage("Unmount failed!\n\n"+output);
return;
}
QProcess remount;
QString hexAddr = QString::number(dirName.toLongLong(), 16).prepend("0x");
QString mntCMD="mount -t hmfs -o physaddr="+ hexAddr +",uid=1000,gid=1000,ro,mnt_cp=" +QString::number(verNum)+" none " + mountPath;
remount.start("sh", QStringList() << "-c" << mntCMD);
if(!remount.waitForStarted()){
errMsg->showMessage("Start remount failed");
return;
}
output = QString(remount.readAllStandardError());
remount.waitForFinished();
if(output!=""){
errMsg->showMessage("Remount failed!\n\n "+output);
return;
}
}
void cpDetail_form::on_btnDelete_clicked()
{
int r = QMessageBox::question(this,"Warning",
"Do you want to delete checkpoint"+QString::number(verNum),
QMessageBox::Yes|QMessageBox::Default,
QMessageBox::No|QMessageBox::Escape);
if(r == QMessageBox::Yes){
QFile cp_file("/sys/kernel/debug/hmfs/" + dirName +"/info");
if(!cp_file.open(QIODevice::ReadWrite)){
errMsg->showMessage("Cannot open file\n");
return;
}
QTextStream out(&cp_file);
out << "cp d "<< verNum <<endl;
QTextStream in(&cp_file);
QString line = in.readLine();
if(line.contains("deleted")) {
errMsg->showMessage("Checkpoint deleted!"
+ QString::number(verNum));
ui->btnDelete->setEnabled(false);
} else {
errMsg->showMessage("Error occurs during deleting checkpoint "
+ QString::number(verNum));
}
}
}