fuse_impls_release.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_dfs.h"
  19. #include "fuse_impls.h"
  20. #include "fuse_file_handle.h"
  21. #include "fuse_connect.h"
  22. #include <stdlib.h>
  23. /**
  24. * release a fuse_file_info structure.
  25. *
  26. * When this function is invoked, there are no more references to our
  27. * fuse_file_info structure that exist anywhere. So there is no need for
  28. * locking to protect this structure here.
  29. *
  30. * Another thread could open() the same file, and get a separate, different file
  31. * descriptor with a different, separate fuse_file_info structure. In HDFS,
  32. * this results in one writer winning and overwriting everything the other
  33. * writer has done.
  34. */
  35. int dfs_release (const char *path, struct fuse_file_info *fi) {
  36. TRACE1("release", path)
  37. // retrieve dfs specific data
  38. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  39. // check params and the context var
  40. assert(path);
  41. assert(dfs);
  42. assert('/' == *path);
  43. int ret = 0;
  44. dfs_fh *fh = (dfs_fh*)fi->fh;
  45. assert(fh);
  46. hdfsFile file_handle = (hdfsFile)fh->hdfsFH;
  47. if (NULL != file_handle) {
  48. if (hdfsCloseFile(hdfsConnGetFs(fh->conn), file_handle) != 0) {
  49. ERROR("Could not close handle %ld for %s\n",(long)file_handle, path);
  50. ret = -EIO;
  51. }
  52. }
  53. free(fh->buf);
  54. hdfsConnRelease(fh->conn);
  55. pthread_mutex_destroy(&fh->mutex);
  56. free(fh);
  57. fi->fh = 0;
  58. return ret;
  59. }