ewmscp  ..
gpfsFcntlHandler.cpp
Go to the documentation of this file.
1 #include <string>
2 #include "gpfsFcntlHandler.h"
3 #include "copyRequestTypes.h"
4 #include "timer.h"
5 #include <throwcall.h>
6 #include <iostream>
7 
9  buffer.header.totalLength = sizeof(buffer.header);
10  buffer.header.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
11  buffer.header.errorOffset = -1;
12  buffer.header.fcntlReserved = 0;
13 }
14 
15 void gpfs_fcntl_handler::call(int fd, const std::string& path) {
16  auto result = gpfs_fcntl(fd, &buffer);
17  if (result) {
18  if (errno == ENOSYS) {
19  throw unimplementedActionError("gpfs_fcntl not implemented here");
20  }
21  switch (buffer.header.errorOffset) {
22  case -1: // unchanged, happens if fd does not point to a file on gpfs
23  throwcall::good0(result, "can't fcntl ", path, ", is not on a gpfs file system");
24  break;
25  case 0:
26 
27  throwcall::good0(result, "can't fcntl ", path,
28  ", wrong version number ", buffer.header.fcntlVersion);
29  break;
30  default:
31  int i = 0;
32  int o = 0;
33  while (o < buffer.header.errorOffset) {
34  std::cerr << o << "\n";
35  o += *reinterpret_cast<const int*>(&buffer.justCharsProvidingSpace[o]);
36  i++;
37  }
38  throwcall::good0(result, "can't fcntl ", path,
39  ", wrong parameter in hint ", i,
40  " at offset ", buffer.header.errorOffset);
41  }
42  }
43 };
44 
46  std::cerr << "dump of fcntl struct at " << (void*)this << "\n";
47  for (int i = 0; i < buffer.header.totalLength; i += sizeof(int)) {
48  std::cerr << *reinterpret_cast<const int*>(&buffer.justCharsProvidingSpace[i]) << "\n";
49  }
50 }
51 
53  buffer.acl.acl_len = sizeof(buffer);
54  buffer.acl.acl_level = GPFS_ACL_LEVEL_BASE;
55  buffer.acl.acl_version = 0;
56  buffer.acl.acl_type = GPFS_ACL_TYPE_NFS4;
57 }
58 gpfs_acl_handler::gpfs_acl_handler(gpfs_aclCount_t nEntries) {
59  buffer.acl.acl_len = reinterpret_cast<char*>(&buffer.acl.ace_v4[nEntries])
60  - reinterpret_cast<char*>(&buffer.acl.acl_len);
61  if (buffer.acl.acl_len > sizeof(buffer)) {
62  throw std::runtime_error("to many entries for gpfs acl");
63  }
64  buffer.acl.acl_level = GPFS_ACL_LEVEL_BASE;
65  buffer.acl.acl_version = GPFS_ACL_VERSION_NFS4;
66  buffer.acl.acl_type = GPFS_ACL_TYPE_NFS4;
67  buffer.acl.acl_nace = nEntries;
68 }
69 
70 const gpfs_ace_v4_t* gpfs_acl_handler::begin() const {
71  if (buffer.acl.acl_version == GPFS_ACL_VERSION_NFS4) {
72  return &buffer.acl.ace_v4[0];
73  } else {
74  return &buffer.acl.v4Level1.ace_v4[0];
75  }
76 }
77 const gpfs_ace_v4_t* gpfs_acl_handler::end() const {
78  if (buffer.acl.acl_version == GPFS_ACL_VERSION_NFS4) {
79  return &buffer.acl.ace_v4[buffer.acl.acl_nace];
80  } else {
81  return &buffer.acl.v4Level1.ace_v4[buffer.acl.acl_nace];
82  }
83 }
84 gpfs_ace_v4_t* gpfs_acl_handler::begin() {
85  if (buffer.acl.acl_version == GPFS_ACL_VERSION_NFS4) {
86  return &buffer.acl.ace_v4[0];
87  } else {
88  return &buffer.acl.v4Level1.ace_v4[0];
89  }
90 }
91 gpfs_ace_v4_t* gpfs_acl_handler::end() {
92  if (buffer.acl.acl_version == GPFS_ACL_VERSION_NFS4) {
93  return &buffer.acl.ace_v4[buffer.acl.acl_nace];
94  } else {
95  return &buffer.acl.v4Level1.ace_v4[buffer.acl.acl_nace];
96  }
97 }
98 
99 void gpfs_acl_handler::get(int fd, const std::string& path) {
100  // use LWE_DATA_LWESEND as test for the existence of gpfs_getacl_fd
101 #ifdef LWE_DATA_LWESEND
102  if (fd != -1) {
103  timerInst(gpfs_getacl_fd);
104  throwcall::good0(gpfs_getacl_fd(fd,
105  GPFS_GETACL_STRUCT,
106  buffer.justTheSpace),
107  "can't get acl for ", path);
108  } else
109 #endif
110  {
111  timerInst(gpfs_getacl);
112  throwcall::good0(gpfs_getacl(path.c_str(),
113  GPFS_GETACL_STRUCT,
114  buffer.justTheSpace),
115  "can't get acl for ", path);
116  }
117  if (buffer.acl.acl_version != GPFS_ACL_VERSION_NFS4 &&
118  buffer.acl.acl_version != GPFS_ACL_VERSION_NFS4F) {
119  throw std::runtime_error("wrong acl version on " + path);
120  }
121 }
122 
123 void gpfs_acl_handler::set(int fd, const std::string& path) {
124 #ifdef LWE_DATA_LWESEND
125  if (fd != -1) {
126  timerInst(gpfs_putacl_fd);
127  throwcall::good0(gpfs_putacl_fd(fd,
128  GPFS_PUTACL_STRUCT,
129  buffer.justTheSpace),
130  "can't set acl for ", path);
131  } else
132 #endif
133  {
134  timerInst(gpfs_putacl);
135  throwcall::good0(gpfs_putacl(path.c_str(),
136  GPFS_PUTACL_STRUCT,
137  buffer.justTheSpace),
138  "can't set acl for ", path);
139  }
140 }
gpfs_fcntl_handler::gpfs_fcntl_handler
gpfs_fcntl_handler()
Definition: gpfsFcntlHandler.cpp:8
copyRequestTypes.h
gpfs_acl_handler::begin
const gpfs_ace_v4_t * begin() const
Definition: gpfsFcntlHandler.cpp:70
unimplementedActionError
class for exceptions that result from unimplemented functions Exceptions of this kind are to be throw...
Definition: copyRequestTypes.h:32
gpfs_acl_handler::buffer
union gpfs_acl_handler::@3 buffer
gpfs_acl_handler::get
void get(int fd, const std::string &path)
Definition: gpfsFcntlHandler.cpp:99
timer.h
throwcall.h
gpfs_fcntl_handler::buffer
union gpfs_fcntl_handler::@2 buffer
gpfs_acl_handler::set
void set(int fd, const std::string &path)
Definition: gpfsFcntlHandler.cpp:123
gpfsFcntlHandler.h
timerInst
#define timerInst(subfunc)
Definition: timer.h:157
gpfs_fcntl_handler::call
void call(int fd, const std::string &path)
Definition: gpfsFcntlHandler.cpp:15
gpfs_acl_handler::gpfs_acl_handler
gpfs_acl_handler()
creates struct for getAcl
Definition: gpfsFcntlHandler.cpp:52
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
gpfs_fcntl_handler::dump
void dump() const
Definition: gpfsFcntlHandler.cpp:45
gpfs_acl_handler::end
const gpfs_ace_v4_t * end() const
Definition: gpfsFcntlHandler.cpp:77