fuse_impls_flush.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "fuse_connect.h"
  19. #include "fuse_dfs.h"
  20. #include "fuse_impls.h"
  21. #include "fuse_file_handle.h"
  22. int dfs_flush(const char *path, struct fuse_file_info *fi) {
  23. TRACE1("flush", path)
  24. // retrieve dfs specific data
  25. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  26. // check params and the context var
  27. assert(path);
  28. assert(dfs);
  29. assert('/' == *path);
  30. assert(fi);
  31. if (NULL == (void*)fi->fh) {
  32. return 0;
  33. }
  34. // note that fuse calls flush on RO files too and hdfs does not like that and will return an error
  35. if (fi->flags & O_WRONLY) {
  36. dfs_fh *fh = (dfs_fh*)fi->fh;
  37. assert(fh);
  38. hdfsFile file_handle = (hdfsFile)fh->hdfsFH;
  39. assert(file_handle);
  40. if (hdfsFlush(hdfsConnGetFs(fh->conn), file_handle) != 0) {
  41. ERROR("Could not flush %lx for %s\n",(long)file_handle, path);
  42. return -EIO;
  43. }
  44. }
  45. return 0;
  46. }