Re: Make libcephfs return error when unmounted?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 11, 2012 at 11:12 AM, Noah Watkins <jayhawk@xxxxxxxxxxx> wrote:
>
> Hi all,
>
> A simple program like this:
>
> int main(int argc, char **argv)
> {
>        int ret;
>        struct ceph_mount_info *cmount;
>
>        ceph_create(&cmount, NULL);
>        //ceph_mount(cmount, NULL);
>        ceph_chdir(cmount, "/");
> }
>
> will segfault because in the below snippet, cmount->get_client() returns
> NULL when ceph_mount(..) has not been been called with success.
>
> extern "C" int ceph_chdir (struct ceph_mount_info *cmount, const char *s)
> {
>        return cmount->get_client()->chdir(s);
> }
>
> It would be very useful to get a uniform error return value rather than
> the fault. Something like this came to mind:
>
> diff --git a/src/libcephfs.cc b/src/libcephfs.cc
> index b1481e6..4751e8f 100644
> --- a/src/libcephfs.cc
> +++ b/src/libcephfs.cc
> @@ -180,6 +180,10 @@ public:
>     return cct;
>   }
>
> +  bool is_mounted(void) {
> +    return mounted;
> +  }
> +
>  private:
>   uint64_t msgr_nonce;
>   bool mounted;
> @@ -282,6 +286,8 @@ extern "C" const char* ceph_getcwd(struct
> ceph_mount_info *cmount)
>
>  extern "C" int ceph_chdir (struct ceph_mount_info *cmount, const char *s)
>  {
> +  if (!cmount->is_mounted())
> +    return -1004;
>   return cmount->get_client()->chdir(s);
>  }
>
> Any thoughts on a good way to handle this?

Also need to check that cmount is initialized.  I'd add a helper:

Client *ceph_get_client(struct ceph_mount_info *cmont)
{
  if (cmount && cmount->is_mounted())
    return cmount->get_client();

  return NULL;
}

extern "C" int ceph_chdir (struct ceph_mount_info *cmount, const char *s)
{
  Client *client = ceph_get_client(cmount);
  if (!client)
    return -EINVAL;

  return client->chdir(s);
}


>
> -Noah--
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux