Commit 6c073a7e authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client:
  rbd: fix safety of rbd_put_client()
  rbd: fix a memory leak in rbd_get_client()
  ceph: create a new session lock to avoid lock inversion
  ceph: fix length validation in parse_reply_info()
  ceph: initialize client debugfs outside of monc->mutex
  ceph: change "ceph.layout" xattr to be "ceph.file.layout"
parents ff05f603 d23a4b3f
...@@ -380,6 +380,7 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, ...@@ -380,6 +380,7 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
rbdc = __rbd_client_find(opt); rbdc = __rbd_client_find(opt);
if (rbdc) { if (rbdc) {
ceph_destroy_options(opt); ceph_destroy_options(opt);
kfree(rbd_opts);
/* using an existing client */ /* using an existing client */
kref_get(&rbdc->kref); kref_get(&rbdc->kref);
...@@ -406,15 +407,15 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, ...@@ -406,15 +407,15 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
/* /*
* Destroy ceph client * Destroy ceph client
*
* Caller must hold node_lock.
*/ */
static void rbd_client_release(struct kref *kref) static void rbd_client_release(struct kref *kref)
{ {
struct rbd_client *rbdc = container_of(kref, struct rbd_client, kref); struct rbd_client *rbdc = container_of(kref, struct rbd_client, kref);
dout("rbd_release_client %p\n", rbdc); dout("rbd_release_client %p\n", rbdc);
spin_lock(&node_lock);
list_del(&rbdc->node); list_del(&rbdc->node);
spin_unlock(&node_lock);
ceph_destroy_client(rbdc->client); ceph_destroy_client(rbdc->client);
kfree(rbdc->rbd_opts); kfree(rbdc->rbd_opts);
...@@ -427,7 +428,9 @@ static void rbd_client_release(struct kref *kref) ...@@ -427,7 +428,9 @@ static void rbd_client_release(struct kref *kref)
*/ */
static void rbd_put_client(struct rbd_device *rbd_dev) static void rbd_put_client(struct rbd_device *rbd_dev)
{ {
spin_lock(&node_lock);
kref_put(&rbd_dev->rbd_client->kref, rbd_client_release); kref_put(&rbd_dev->rbd_client->kref, rbd_client_release);
spin_unlock(&node_lock);
rbd_dev->rbd_client = NULL; rbd_dev->rbd_client = NULL;
rbd_dev->client = NULL; rbd_dev->client = NULL;
} }
......
...@@ -641,10 +641,10 @@ static int __cap_is_valid(struct ceph_cap *cap) ...@@ -641,10 +641,10 @@ static int __cap_is_valid(struct ceph_cap *cap)
unsigned long ttl; unsigned long ttl;
u32 gen; u32 gen;
spin_lock(&cap->session->s_cap_lock); spin_lock(&cap->session->s_gen_ttl_lock);
gen = cap->session->s_cap_gen; gen = cap->session->s_cap_gen;
ttl = cap->session->s_cap_ttl; ttl = cap->session->s_cap_ttl;
spin_unlock(&cap->session->s_cap_lock); spin_unlock(&cap->session->s_gen_ttl_lock);
if (cap->cap_gen < gen || time_after_eq(jiffies, ttl)) { if (cap->cap_gen < gen || time_after_eq(jiffies, ttl)) {
dout("__cap_is_valid %p cap %p issued %s " dout("__cap_is_valid %p cap %p issued %s "
......
...@@ -975,10 +975,10 @@ static int dentry_lease_is_valid(struct dentry *dentry) ...@@ -975,10 +975,10 @@ static int dentry_lease_is_valid(struct dentry *dentry)
di = ceph_dentry(dentry); di = ceph_dentry(dentry);
if (di->lease_session) { if (di->lease_session) {
s = di->lease_session; s = di->lease_session;
spin_lock(&s->s_cap_lock); spin_lock(&s->s_gen_ttl_lock);
gen = s->s_cap_gen; gen = s->s_cap_gen;
ttl = s->s_cap_ttl; ttl = s->s_cap_ttl;
spin_unlock(&s->s_cap_lock); spin_unlock(&s->s_gen_ttl_lock);
if (di->lease_gen == gen && if (di->lease_gen == gen &&
time_before(jiffies, dentry->d_time) && time_before(jiffies, dentry->d_time) &&
......
...@@ -262,6 +262,7 @@ static int parse_reply_info(struct ceph_msg *msg, ...@@ -262,6 +262,7 @@ static int parse_reply_info(struct ceph_msg *msg,
/* trace */ /* trace */
ceph_decode_32_safe(&p, end, len, bad); ceph_decode_32_safe(&p, end, len, bad);
if (len > 0) { if (len > 0) {
ceph_decode_need(&p, end, len, bad);
err = parse_reply_info_trace(&p, p+len, info, features); err = parse_reply_info_trace(&p, p+len, info, features);
if (err < 0) if (err < 0)
goto out_bad; goto out_bad;
...@@ -270,6 +271,7 @@ static int parse_reply_info(struct ceph_msg *msg, ...@@ -270,6 +271,7 @@ static int parse_reply_info(struct ceph_msg *msg,
/* extra */ /* extra */
ceph_decode_32_safe(&p, end, len, bad); ceph_decode_32_safe(&p, end, len, bad);
if (len > 0) { if (len > 0) {
ceph_decode_need(&p, end, len, bad);
err = parse_reply_info_extra(&p, p+len, info, features); err = parse_reply_info_extra(&p, p+len, info, features);
if (err < 0) if (err < 0)
goto out_bad; goto out_bad;
...@@ -398,9 +400,11 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, ...@@ -398,9 +400,11 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS; s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS;
s->s_con.peer_name.num = cpu_to_le64(mds); s->s_con.peer_name.num = cpu_to_le64(mds);
spin_lock_init(&s->s_cap_lock); spin_lock_init(&s->s_gen_ttl_lock);
s->s_cap_gen = 0; s->s_cap_gen = 0;
s->s_cap_ttl = 0; s->s_cap_ttl = 0;
spin_lock_init(&s->s_cap_lock);
s->s_renew_requested = 0; s->s_renew_requested = 0;
s->s_renew_seq = 0; s->s_renew_seq = 0;
INIT_LIST_HEAD(&s->s_caps); INIT_LIST_HEAD(&s->s_caps);
...@@ -2326,10 +2330,10 @@ static void handle_session(struct ceph_mds_session *session, ...@@ -2326,10 +2330,10 @@ static void handle_session(struct ceph_mds_session *session,
case CEPH_SESSION_STALE: case CEPH_SESSION_STALE:
pr_info("mds%d caps went stale, renewing\n", pr_info("mds%d caps went stale, renewing\n",
session->s_mds); session->s_mds);
spin_lock(&session->s_cap_lock); spin_lock(&session->s_gen_ttl_lock);
session->s_cap_gen++; session->s_cap_gen++;
session->s_cap_ttl = 0; session->s_cap_ttl = 0;
spin_unlock(&session->s_cap_lock); spin_unlock(&session->s_gen_ttl_lock);
send_renew_caps(mdsc, session); send_renew_caps(mdsc, session);
break; break;
......
...@@ -117,10 +117,13 @@ struct ceph_mds_session { ...@@ -117,10 +117,13 @@ struct ceph_mds_session {
void *s_authorizer_buf, *s_authorizer_reply_buf; void *s_authorizer_buf, *s_authorizer_reply_buf;
size_t s_authorizer_buf_len, s_authorizer_reply_buf_len; size_t s_authorizer_buf_len, s_authorizer_reply_buf_len;
/* protected by s_cap_lock */ /* protected by s_gen_ttl_lock */
spinlock_t s_cap_lock; spinlock_t s_gen_ttl_lock;
u32 s_cap_gen; /* inc each time we get mds stale msg */ u32 s_cap_gen; /* inc each time we get mds stale msg */
unsigned long s_cap_ttl; /* when session caps expire */ unsigned long s_cap_ttl; /* when session caps expire */
/* protected by s_cap_lock */
spinlock_t s_cap_lock;
struct list_head s_caps; /* all caps issued by this session */ struct list_head s_caps; /* all caps issued by this session */
int s_nr_caps, s_trim_caps; int s_nr_caps, s_trim_caps;
int s_num_cap_releases; int s_num_cap_releases;
......
...@@ -111,8 +111,10 @@ static size_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val, ...@@ -111,8 +111,10 @@ static size_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
} }
static struct ceph_vxattr_cb ceph_file_vxattrs[] = { static struct ceph_vxattr_cb ceph_file_vxattrs[] = {
{ true, "ceph.file.layout", ceph_vxattrcb_layout},
/* The following extended attribute name is deprecated */
{ true, "ceph.layout", ceph_vxattrcb_layout}, { true, "ceph.layout", ceph_vxattrcb_layout},
{ NULL, NULL } { true, NULL, NULL }
}; };
static struct ceph_vxattr_cb *ceph_inode_vxattrs(struct inode *inode) static struct ceph_vxattr_cb *ceph_inode_vxattrs(struct inode *inode)
......
...@@ -85,8 +85,6 @@ int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid) ...@@ -85,8 +85,6 @@ int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid)
} else { } else {
pr_info("client%lld fsid %pU\n", ceph_client_id(client), fsid); pr_info("client%lld fsid %pU\n", ceph_client_id(client), fsid);
memcpy(&client->fsid, fsid, sizeof(*fsid)); memcpy(&client->fsid, fsid, sizeof(*fsid));
ceph_debugfs_client_init(client);
client->have_fsid = true;
} }
return 0; return 0;
} }
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <linux/ceph/mon_client.h> #include <linux/ceph/mon_client.h>
#include <linux/ceph/libceph.h> #include <linux/ceph/libceph.h>
#include <linux/ceph/debugfs.h>
#include <linux/ceph/decode.h> #include <linux/ceph/decode.h>
#include <linux/ceph/auth.h> #include <linux/ceph/auth.h>
/* /*
...@@ -340,8 +340,19 @@ static void ceph_monc_handle_map(struct ceph_mon_client *monc, ...@@ -340,8 +340,19 @@ static void ceph_monc_handle_map(struct ceph_mon_client *monc,
client->monc.monmap = monmap; client->monc.monmap = monmap;
kfree(old); kfree(old);
if (!client->have_fsid) {
client->have_fsid = true;
mutex_unlock(&monc->mutex);
/*
* do debugfs initialization without mutex to avoid
* creating a locking dependency
*/
ceph_debugfs_client_init(client);
goto out_unlocked;
}
out: out:
mutex_unlock(&monc->mutex); mutex_unlock(&monc->mutex);
out_unlocked:
wake_up_all(&client->auth_wq); wake_up_all(&client->auth_wq);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment