35
35
import org .apache .hadoop .fs .RawLocalFileSystem ;
36
36
import org .slf4j .Logger ;
37
37
import org .slf4j .LoggerFactory ;
38
+ import org .apache .hadoop .fs .permission .FsPermission ;
38
39
39
40
public class GlusterVolume extends RawLocalFileSystem {
40
41
@@ -43,6 +44,8 @@ public class GlusterVolume extends RawLocalFileSystem{
43
44
public static final URI NAME = URI .create ("glusterfs:///" );
44
45
45
46
protected String root =null ;
47
+ protected String superUser =null ;
48
+ protected AclPathFilter aclFilter = null ;
46
49
47
50
protected static GlusterFSXattr attr = null ;
48
51
@@ -81,6 +84,10 @@ public void setConf(Configuration conf){
81
84
mkdirs (mapredSysDirectory );
82
85
}
83
86
87
+ superUser = conf .get ("gluster.daemon.user" , null );
88
+
89
+ aclFilter = new AclPathFilter (conf );
90
+
84
91
/* ensure the initial working directory exists */
85
92
Path workingDirectory = getInitialWorkingDirectory ();
86
93
mkdirs (workingDirectory );
@@ -104,7 +111,7 @@ public File pathToFile(Path path) {
104
111
}
105
112
106
113
@ Override
107
- protected Path getInitialWorkingDirectory () {
114
+ protected Path getInitialWorkingDirectory () {
108
115
/* apache's unit tests use a default working direcotry like this: */
109
116
return new Path (this .NAME + "user/" + System .getProperty ("user.name" ));
110
117
/* The super impl returns the users home directory in unix */
@@ -113,9 +120,9 @@ protected Path getInitialWorkingDirectory() {
113
120
114
121
public Path fileToPath (File path ) {
115
122
return new Path (NAME .toString () + path .toURI ().getRawPath ().substring (root .length ()));
116
- }
123
+ }
117
124
118
- public boolean rename (Path src , Path dst ) throws IOException {
125
+ public boolean rename (Path src , Path dst ) throws IOException {
119
126
File dest = pathToFile (dst );
120
127
121
128
/* two HCFS semantics java.io.File doesn't honor */
@@ -200,7 +207,36 @@ public long getBlockSize(Path path) throws IOException{
200
207
201
208
return blkSz ;
202
209
}
203
-
210
+ /*
211
+ * ensures the 'super user' is given read/write access.
212
+ * the ACL drops off after a chmod or chown.
213
+ */
214
+
215
+ private void updateAcl (Path p ){
216
+ if (superUser !=null && aclFilter .matches (p ) ){
217
+ File f = pathToFile (p );
218
+ String path = f .getAbsolutePath ();
219
+ String command = "setfacl -m u:" + superUser + ":rwx " + path ;
220
+ try {
221
+ Runtime .getRuntime ().exec (command );
222
+ }catch (IOException ex ){
223
+ throw new RuntimeException (ex );
224
+ }
225
+ }
226
+ }
227
+
228
+ public void setOwner (Path p , String username , String groupname )
229
+ throws IOException {
230
+ super .setOwner (p ,username ,groupname );
231
+ updateAcl (p );
232
+
233
+ }
234
+
235
+ public void setPermission (Path p , FsPermission permission )
236
+ throws IOException {
237
+ super .setPermission (p ,permission );
238
+ updateAcl (p );
239
+ }
204
240
public BlockLocation [] getFileBlockLocations (FileStatus file ,long start ,long len ) throws IOException {
205
241
File f =pathToFile (file .getPath ());
206
242
BlockLocation [] result =null ;
0 commit comments