From: Greg Farnum Date: Fri, 7 Aug 2009 22:54:33 +0000 (-0700) Subject: Hadoop: Added setTimes to CephFileSystem and CephFSInterface. X-Git-Tag: v0.13~114 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=08dc661f3c91a186ef96e497463ad96f567bcf5c;p=ceph.git Hadoop: Added setTimes to CephFileSystem and CephFSInterface. --- diff --git a/src/client/hadoop/CephFSInterface.cc b/src/client/hadoop/CephFSInterface.cc index 293972ce9dba..13ac0163e87a 100644 --- a/src/client/hadoop/CephFSInterface.cc +++ b/src/client/hadoop/CephFSInterface.cc @@ -535,6 +535,28 @@ JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1ho return env->NewStringUTF(address.c_str()); } +/* + * Class: org_apache_hadoop_fs_ceph_CephFileSystem + * Method: ceph_setTimes + * Signature: (Ljava/lang/String;JJ)I + */ +JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setTimes +(JNIEnv * env, jobject obj, jstring j_path, jlong mtime, jlong atime) { + const char *c_path = env->GetStringUTFChars(j_path, 0); + if(c_path == NULL) return -ENOMEM; + + //build the mask for ceph_setattr + int mask = 0; + if (mtime!=-1) mask = CEPH_SETATTR_MTIME; + if (atime!=-1) mask |= CEPH_SETTATTR_ATIME; + //build a struct stat and fill it in! + struct stat attr; + attr.st_mtime = mtime; + attr.st_atime = atime; + //may need to fill in uid and gid here later on... + ceph_setattr(c_path, &attr, mask); +} + /* * Class: org_apache_hadoop_fs_ceph_CephInputStream * Method: ceph_read diff --git a/src/client/hadoop/CephFSInterface.h b/src/client/hadoop/CephFSInterface.h index abcff972be88..03bc5c9ced08 100644 --- a/src/client/hadoop/CephFSInterface.h +++ b/src/client/hadoop/CephFSInterface.h @@ -190,6 +190,14 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1repli JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1hosts (JNIEnv *, jobject, jint, jlong); +/* + * Class: org_apache_hadoop_fs_ceph_CephFileSystem + * Method: ceph_setTimes + * Signature: (Ljava/lang/String;JJ)I + */ +JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setTimes + (JNIEnv *, jobject, jstring, jlong, jlong); + /* * Class: org_apache_hadoop_fs_ceph_CephInputStream * Method: ceph_read diff --git a/src/client/hadoop/ceph/CephFileSystem.java b/src/client/hadoop/ceph/CephFileSystem.java index 2f3ba63ad521..c32b125c9f7c 100644 --- a/src/client/hadoop/ceph/CephFileSystem.java +++ b/src/client/hadoop/ceph/CephFileSystem.java @@ -72,6 +72,7 @@ public class CephFileSystem extends FileSystem { private native boolean ceph_stat(String path, Stat fill); private native int ceph_replication(String path); private native String ceph_hosts(int fh, long offset); + private native int ceph_setTimes(String path, long mtime, long atime); public CephFileSystem() { debug("CephFileSystem:enter"); @@ -335,6 +336,26 @@ public class CephFileSystem extends FileSystem { ceph_setPermission(abs_path.toString(), permission.toShort()); } + /** + * Set access/modification times of a file. + * @param p The path + * @param mtime Set modification time in number of millis since Jan 1, 1970. + * @param atime Set access time in number of millis since Jan 1, 1970. + */ +@Override + public void setTimes(Path p, long mtime, long atime) throws IOException { + if (!initialized) throw new IOException ("You have to initialize the" + +"CephFileSystem before calling other methods."); + Path abs_path = makeAbsolute(p); + //libhadoopcephfs respects the -1 "don't set" meanings, but we + //need to convert these times in millis to times in seconds here + if (mtime != -1) mtime /= 1000; + if (atime != -1) atime /= 1000; + int r = ceph_setTimes(abs_path.toString(), mtime, atime); + if (r<0) throw new IOException ("Failed to set times on path " + + abs_path.toString() + " Error code: " + r); +} + /** * In order to run this with Hadoop .20, I had to revert back to using * a boolean instead of the CreateFlag. diff --git a/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h b/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h index 2be8bcdc76d6..99beb5d6ae6e 100644 --- a/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h +++ b/src/client/hadoop/org_apache_hadoop_fs_ceph_CephFileSystem.h @@ -17,22 +17,6 @@ extern "C" { JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1initializeClient (JNIEnv *, jobject, jstring, jstring); -/* - * Class: org_apache_hadoop_fs_ceph_CephFileSystem - * Method: ceph_copyFromLocalFile - * Signature: (Ljava/lang/String;Ljava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyFromLocalFile - (JNIEnv *, jobject, jstring, jstring); - -/* - * Class: org_apache_hadoop_fs_ceph_CephFileSystem - * Method: ceph_copyToLocalFile - * Signature: (Ljava/lang/String;Ljava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyToLocalFile - (JNIEnv *, jobject, jstring, jstring); - /* * Class: org_apache_hadoop_fs_ceph_CephFileSystem * Method: ceph_getcwd @@ -209,6 +193,14 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1repli JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1hosts (JNIEnv *, jobject, jint, jlong); +/* + * Class: org_apache_hadoop_fs_ceph_CephFileSystem + * Method: ceph_setTimes + * Signature: (Ljava/lang/String;JJ)I + */ +JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setTimes + (JNIEnv *, jobject, jstring, jlong, jlong); + #ifdef __cplusplus } #endif