- use le32 etc annotation
- probably kill base case in encoder.h, replace with int types, with appropriate swabbing?
- addr=?
-- fix ceph_lookup_open
kernel client
- make sure link/unlink results reflected by inode/dentry cache (let fill_trace do it? invalidate? do actual update?)
#include "include/types.h"
#include <fstream>
#include <stdlib.h>
+#include <errno.h>
// hack hack hack ugly FIXME
#include "include/atomic.h"
#include "osd/osd_types.h"
+int buffer::list::read_file(const char *fn)
+{
+ struct stat st;
+ int fd = ::open(fn, O_RDONLY);
+ if (fd < 0) {
+ cerr << "can't open " << fn << ": " << strerror(errno) << std::endl;
+ return -errno;
+ }
+ ::fstat(fd, &st);
+ bufferptr bp(st.st_size);
+ append(bp);
+ ::read(fd, (void*)c_str(), length());
+ ::close(fd);
+ return 0;
+}
+
+int buffer::list::write_file(const char *fn)
+{
+ int fd = ::open(fn, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ if (fd < 0) {
+ cerr << "can't write " << fn << ": " << strerror(errno) << std::endl;
+ return -errno;
+ }
+ ::write(fd, (void*)c_str(), length());
+ ::close(fd);
+ return 0;
+}
+
+
+
// debug output
Mutex _dout_lock;
ostream *_dout = &std::cout;
out[i] = rawout[i];
}
+ int read_from_file(const char *fn) {
+ bufferlist bl;
+ int r = bl.read_file(fn);
+ if (r < 0) return r;
+ bufferlist::iterator blp = bl.begin();
+ _decode(blp);
+ return 0;
+ }
+ int write_to_file(const char *fn) {
+ bufferlist bl;
+ _encode(bl);
+ return bl.write_file(fn);
+ }
+
void _encode(bufferlist &bl, bool lean=false) {
::_encode_simple(crush->max_buckets, bl);
::_encode_simple(crush->max_rules, bl);
I32 len;
int i;
SV **tv;
- int view;
+// int view;
//printf("typemap\n");
out.unsetf(std::ios::right);
}
+ int read_file(const char *fn);
+ int write_file(const char *fn);
+
};
};
exit(1);
}
-int read_file(const char *fn, bufferlist &bl)
-{
- struct stat st;
- int fd = ::open(fn, O_RDONLY);
- if (fd < 0) {
- cerr << "can't open " << fn << ": " << strerror(errno) << std::endl;
- return -errno;
- }
- ::fstat(fd, &st);
- bufferptr bp(st.st_size);
- bl.append(bp);
- ::read(fd, (void*)bl.c_str(), bl.length());
- ::close(fd);
- return 0;
-}
-
int main(int argc, const char **argv)
{
// load monmap
bufferlist monmapbl;
- int err = read_file(monmapfn, monmapbl);
+ int err = monmapbl.read_file(monmapfn);
if (err < 0)
exit(1);
MonMap monmap;
bufferlist bl;
encode(bl);
- // write
- int fd = ::open(fn, O_RDWR|O_CREAT);
- if (fd < 0) return fd;
- ::fchmod(fd, 0644);
- ::write(fd, (void*)bl.c_str(), bl.length());
- ::close(fd);
- return 0;
+ return bl.write_file(fn);
}
int MonMap::read(const char *fn)
{
// read
bufferlist bl;
- int fd = ::open(fn, O_RDONLY);
- if (fd < 0) return -errno;
- struct stat st;
- ::fstat(fd, &st);
- bufferptr bp(st.st_size);
- bl.append(bp);
- ::read(fd, (void*)bl.c_str(), bl.length());
- ::close(fd);
-
- // decode
+ int r = bl.read_file(fn);
+ if (r < 0)
+ return r;
decode(bl);
return 0;
}
*/
}
-int read_file(const char *fn, bufferlist &bl)
-{
- struct stat st;
- int fd = ::open(fn, O_RDONLY);
- if (fd < 0) {
- cerr << "can't open " << fn << ": " << strerror(errno) << std::endl;
- return -errno;
- }
- ::fstat(fd, &st);
- bufferptr bp(st.st_size);
- bl.append(bp);
- ::read(fd, (void*)bl.c_str(), bl.length());
- ::close(fd);
- return 0;
-}
-
-int write_file(const char *fn, bufferlist &bl)
-{
- int fd = ::open(fn, O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (fd < 0) {
- cerr << "can't write " << fn << ": " << strerror(errno) << std::endl;
- return -errno;
- }
- ::write(fd, (void*)bl.c_str(), bl.length());
- ::close(fd);
- return 0;
-}
int main(int argc, const char **argv)
{
int r = 0;
if (!(createsimple && clobber))
- r = read_file(fn, bl);
+ r = bl.read_file(fn);
if (!createsimple && r < 0) {
cerr << me << ": couldn't open " << fn << ": " << strerror(errno) << std::endl;
return -1;
if (import_crush) {
bufferlist cbl;
- r = read_file(import_crush, cbl);
+ r = cbl.read_file(import_crush);
if (r < 0) {
cerr << me << ": error reading crush map from " << import_crush << std::endl;
exit(1);
if (export_crush) {
bufferlist cbl;
osdmap.crush._encode(cbl);
- r = write_file(export_crush, cbl);
+ r = cbl.write_file(export_crush);
if (r < 0) {
cerr << me << ": error writing crush map to " << import_crush << std::endl;
exit(1);
cout << me << ": writing epoch " << osdmap.get_epoch()
<< " to " << fn
<< std::endl;
- int r = write_file(fn, bl);
+ int r = bl.write_file(fn);
assert(r >= 0);
}