14d3d5aa8SLars Ellenberg #define pr_fmt(fmt) "drbd debugfs: " fmt 24d3d5aa8SLars Ellenberg #include <linux/kernel.h> 34d3d5aa8SLars Ellenberg #include <linux/module.h> 44d3d5aa8SLars Ellenberg #include <linux/debugfs.h> 5db1866ffSLars Ellenberg #include <linux/seq_file.h> 64d3d5aa8SLars Ellenberg #include <linux/stat.h> 7db1866ffSLars Ellenberg #include <linux/jiffies.h> 84d3d5aa8SLars Ellenberg #include <linux/list.h> 94d3d5aa8SLars Ellenberg 104d3d5aa8SLars Ellenberg #include "drbd_int.h" 114d3d5aa8SLars Ellenberg #include "drbd_req.h" 124d3d5aa8SLars Ellenberg #include "drbd_debugfs.h" 134d3d5aa8SLars Ellenberg 144d3d5aa8SLars Ellenberg static struct dentry *drbd_debugfs_root; 154d3d5aa8SLars Ellenberg static struct dentry *drbd_debugfs_resources; 164d3d5aa8SLars Ellenberg static struct dentry *drbd_debugfs_minors; 174d3d5aa8SLars Ellenberg 18db1866ffSLars Ellenberg static void seq_print_age_or_dash(struct seq_file *m, bool valid, unsigned long dt) 19db1866ffSLars Ellenberg { 20db1866ffSLars Ellenberg if (valid) 21db1866ffSLars Ellenberg seq_printf(m, "\t%d", jiffies_to_msecs(dt)); 22db1866ffSLars Ellenberg else 23db1866ffSLars Ellenberg seq_printf(m, "\t-"); 24db1866ffSLars Ellenberg } 25db1866ffSLars Ellenberg 26f418815fSLars Ellenberg static void __seq_print_rq_state_bit(struct seq_file *m, 27f418815fSLars Ellenberg bool is_set, char *sep, const char *set_name, const char *unset_name) 28db1866ffSLars Ellenberg { 29f418815fSLars Ellenberg if (is_set && set_name) { 30db1866ffSLars Ellenberg seq_putc(m, *sep); 31f418815fSLars Ellenberg seq_puts(m, set_name); 32db1866ffSLars Ellenberg *sep = '|'; 33f418815fSLars Ellenberg } else if (!is_set && unset_name) { 34f418815fSLars Ellenberg seq_putc(m, *sep); 35f418815fSLars Ellenberg seq_puts(m, unset_name); 36f418815fSLars Ellenberg *sep = '|'; 37f418815fSLars Ellenberg } 38f418815fSLars Ellenberg } 39f418815fSLars Ellenberg 40f418815fSLars Ellenberg static void seq_print_rq_state_bit(struct seq_file *m, 41f418815fSLars Ellenberg bool is_set, char *sep, const char *set_name) 42f418815fSLars Ellenberg { 43f418815fSLars Ellenberg __seq_print_rq_state_bit(m, is_set, sep, set_name, NULL); 44db1866ffSLars Ellenberg } 45db1866ffSLars Ellenberg 46db1866ffSLars Ellenberg /* pretty print enum drbd_req_state_bits req->rq_state */ 47db1866ffSLars Ellenberg static void seq_print_request_state(struct seq_file *m, struct drbd_request *req) 48db1866ffSLars Ellenberg { 49db1866ffSLars Ellenberg unsigned int s = req->rq_state; 50db1866ffSLars Ellenberg char sep = ' '; 51db1866ffSLars Ellenberg seq_printf(m, "\t0x%08x", s); 52db1866ffSLars Ellenberg seq_printf(m, "\tmaster: %s", req->master_bio ? "pending" : "completed"); 53db1866ffSLars Ellenberg 54db1866ffSLars Ellenberg /* RQ_WRITE ignored, already reported */ 55db1866ffSLars Ellenberg seq_puts(m, "\tlocal:"); 56db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_IN_ACT_LOG, &sep, "in-AL"); 57db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_POSTPONED, &sep, "postponed"); 58db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_COMPLETION_SUSP, &sep, "suspended"); 59db1866ffSLars Ellenberg sep = ' '; 60db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_LOCAL_PENDING, &sep, "pending"); 61db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_LOCAL_COMPLETED, &sep, "completed"); 62db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_LOCAL_ABORTED, &sep, "aborted"); 63db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_LOCAL_OK, &sep, "ok"); 64db1866ffSLars Ellenberg if (sep == ' ') 65db1866ffSLars Ellenberg seq_puts(m, " -"); 66db1866ffSLars Ellenberg 67db1866ffSLars Ellenberg /* for_each_connection ... */ 68db1866ffSLars Ellenberg seq_printf(m, "\tnet:"); 69db1866ffSLars Ellenberg sep = ' '; 70db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_NET_PENDING, &sep, "pending"); 71db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_NET_QUEUED, &sep, "queued"); 72db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_NET_SENT, &sep, "sent"); 73db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_NET_DONE, &sep, "done"); 74db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_NET_SIS, &sep, "sis"); 75db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_NET_OK, &sep, "ok"); 76db1866ffSLars Ellenberg if (sep == ' ') 77db1866ffSLars Ellenberg seq_puts(m, " -"); 78db1866ffSLars Ellenberg 79db1866ffSLars Ellenberg seq_printf(m, " :"); 80db1866ffSLars Ellenberg sep = ' '; 81db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_EXP_RECEIVE_ACK, &sep, "B"); 82db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_EXP_WRITE_ACK, &sep, "C"); 83db1866ffSLars Ellenberg seq_print_rq_state_bit(m, s & RQ_EXP_BARR_ACK, &sep, "barr"); 84db1866ffSLars Ellenberg if (sep == ' ') 85db1866ffSLars Ellenberg seq_puts(m, " -"); 86db1866ffSLars Ellenberg seq_printf(m, "\n"); 87db1866ffSLars Ellenberg } 88db1866ffSLars Ellenberg 89db1866ffSLars Ellenberg static void seq_print_one_request(struct seq_file *m, struct drbd_request *req, unsigned long now) 90db1866ffSLars Ellenberg { 91db1866ffSLars Ellenberg /* change anything here, fixup header below! */ 92db1866ffSLars Ellenberg unsigned int s = req->rq_state; 93db1866ffSLars Ellenberg 94db1866ffSLars Ellenberg #define RQ_HDR_1 "epoch\tsector\tsize\trw" 95db1866ffSLars Ellenberg seq_printf(m, "0x%x\t%llu\t%u\t%s", 96db1866ffSLars Ellenberg req->epoch, 97db1866ffSLars Ellenberg (unsigned long long)req->i.sector, req->i.size >> 9, 98db1866ffSLars Ellenberg (s & RQ_WRITE) ? "W" : "R"); 99db1866ffSLars Ellenberg 100db1866ffSLars Ellenberg #define RQ_HDR_2 "\tstart\tin AL\tsubmit" 101db1866ffSLars Ellenberg seq_printf(m, "\t%d", jiffies_to_msecs(now - req->start_jif)); 102db1866ffSLars Ellenberg seq_print_age_or_dash(m, s & RQ_IN_ACT_LOG, now - req->in_actlog_jif); 103db1866ffSLars Ellenberg seq_print_age_or_dash(m, s & RQ_LOCAL_PENDING, now - req->pre_submit_jif); 104db1866ffSLars Ellenberg 105db1866ffSLars Ellenberg #define RQ_HDR_3 "\tsent\tacked\tdone" 106db1866ffSLars Ellenberg seq_print_age_or_dash(m, s & RQ_NET_SENT, now - req->pre_send_jif); 107db1866ffSLars Ellenberg seq_print_age_or_dash(m, (s & RQ_NET_SENT) && !(s & RQ_NET_PENDING), now - req->acked_jif); 108db1866ffSLars Ellenberg seq_print_age_or_dash(m, s & RQ_NET_DONE, now - req->net_done_jif); 109db1866ffSLars Ellenberg 110db1866ffSLars Ellenberg #define RQ_HDR_4 "\tstate\n" 111db1866ffSLars Ellenberg seq_print_request_state(m, req); 112db1866ffSLars Ellenberg } 113db1866ffSLars Ellenberg #define RQ_HDR RQ_HDR_1 RQ_HDR_2 RQ_HDR_3 RQ_HDR_4 114db1866ffSLars Ellenberg 115db1866ffSLars Ellenberg static void seq_print_minor_vnr_req(struct seq_file *m, struct drbd_request *req, unsigned long now) 116db1866ffSLars Ellenberg { 117db1866ffSLars Ellenberg seq_printf(m, "%u\t%u\t", req->device->minor, req->device->vnr); 118db1866ffSLars Ellenberg seq_print_one_request(m, req, now); 119db1866ffSLars Ellenberg } 120db1866ffSLars Ellenberg 121f418815fSLars Ellenberg static void seq_print_resource_pending_meta_io(struct seq_file *m, struct drbd_resource *resource, unsigned long now) 122f418815fSLars Ellenberg { 123f418815fSLars Ellenberg struct drbd_device *device; 124f418815fSLars Ellenberg unsigned int i; 125f418815fSLars Ellenberg 126f418815fSLars Ellenberg seq_puts(m, "minor\tvnr\tstart\tsubmit\tintent\n"); 127f418815fSLars Ellenberg rcu_read_lock(); 128f418815fSLars Ellenberg idr_for_each_entry(&resource->devices, device, i) { 129f418815fSLars Ellenberg struct drbd_md_io tmp; 130f418815fSLars Ellenberg /* In theory this is racy, 131f418815fSLars Ellenberg * in the sense that there could have been a 132f418815fSLars Ellenberg * drbd_md_put_buffer(); drbd_md_get_buffer(); 133f418815fSLars Ellenberg * between accessing these members here. */ 134f418815fSLars Ellenberg tmp = device->md_io; 135f418815fSLars Ellenberg if (atomic_read(&tmp.in_use)) { 136f418815fSLars Ellenberg seq_printf(m, "%u\t%u\t%d\t", 137f418815fSLars Ellenberg device->minor, device->vnr, 138f418815fSLars Ellenberg jiffies_to_msecs(now - tmp.start_jif)); 139f418815fSLars Ellenberg if (time_before(tmp.submit_jif, tmp.start_jif)) 140f418815fSLars Ellenberg seq_puts(m, "-\t"); 141f418815fSLars Ellenberg else 142f418815fSLars Ellenberg seq_printf(m, "%d\t", jiffies_to_msecs(now - tmp.submit_jif)); 143f418815fSLars Ellenberg seq_printf(m, "%s\n", tmp.current_use); 144f418815fSLars Ellenberg } 145f418815fSLars Ellenberg } 146f418815fSLars Ellenberg rcu_read_unlock(); 147f418815fSLars Ellenberg } 148f418815fSLars Ellenberg 149f418815fSLars Ellenberg static void seq_print_waiting_for_AL(struct seq_file *m, struct drbd_resource *resource, unsigned long now) 150f418815fSLars Ellenberg { 151f418815fSLars Ellenberg struct drbd_device *device; 152f418815fSLars Ellenberg unsigned int i; 153f418815fSLars Ellenberg 154f418815fSLars Ellenberg seq_puts(m, "minor\tvnr\tage\t#waiting\n"); 155f418815fSLars Ellenberg rcu_read_lock(); 156f418815fSLars Ellenberg idr_for_each_entry(&resource->devices, device, i) { 157f418815fSLars Ellenberg unsigned long jif; 158f418815fSLars Ellenberg struct drbd_request *req; 159f418815fSLars Ellenberg int n = atomic_read(&device->ap_actlog_cnt); 160f418815fSLars Ellenberg if (n) { 161f418815fSLars Ellenberg spin_lock_irq(&device->resource->req_lock); 162f418815fSLars Ellenberg req = list_first_entry_or_null(&device->pending_master_completion[1], 163f418815fSLars Ellenberg struct drbd_request, req_pending_master_completion); 164f418815fSLars Ellenberg /* if the oldest request does not wait for the activity log 165f418815fSLars Ellenberg * it is not interesting for us here */ 166f418815fSLars Ellenberg if (req && !(req->rq_state & RQ_IN_ACT_LOG)) 167f418815fSLars Ellenberg jif = req->start_jif; 168f418815fSLars Ellenberg else 169f418815fSLars Ellenberg req = NULL; 170f418815fSLars Ellenberg spin_unlock_irq(&device->resource->req_lock); 171f418815fSLars Ellenberg } 172f418815fSLars Ellenberg if (n) { 173f418815fSLars Ellenberg seq_printf(m, "%u\t%u\t", device->minor, device->vnr); 174f418815fSLars Ellenberg if (req) 175f418815fSLars Ellenberg seq_printf(m, "%u\t", jiffies_to_msecs(now - jif)); 176f418815fSLars Ellenberg else 177f418815fSLars Ellenberg seq_puts(m, "-\t"); 178f418815fSLars Ellenberg seq_printf(m, "%u\n", n); 179f418815fSLars Ellenberg } 180f418815fSLars Ellenberg } 181f418815fSLars Ellenberg rcu_read_unlock(); 182f418815fSLars Ellenberg } 183f418815fSLars Ellenberg 184f418815fSLars Ellenberg static void seq_print_device_bitmap_io(struct seq_file *m, struct drbd_device *device, unsigned long now) 185f418815fSLars Ellenberg { 186f418815fSLars Ellenberg struct drbd_bm_aio_ctx *ctx; 187f418815fSLars Ellenberg unsigned long start_jif; 188f418815fSLars Ellenberg unsigned int in_flight; 189f418815fSLars Ellenberg unsigned int flags; 190f418815fSLars Ellenberg spin_lock_irq(&device->resource->req_lock); 191f418815fSLars Ellenberg ctx = list_first_entry_or_null(&device->pending_bitmap_io, struct drbd_bm_aio_ctx, list); 192f418815fSLars Ellenberg if (ctx && ctx->done) 193f418815fSLars Ellenberg ctx = NULL; 194f418815fSLars Ellenberg if (ctx) { 195f418815fSLars Ellenberg start_jif = ctx->start_jif; 196f418815fSLars Ellenberg in_flight = atomic_read(&ctx->in_flight); 197f418815fSLars Ellenberg flags = ctx->flags; 198f418815fSLars Ellenberg } 199f418815fSLars Ellenberg spin_unlock_irq(&device->resource->req_lock); 200f418815fSLars Ellenberg if (ctx) { 201f418815fSLars Ellenberg seq_printf(m, "%u\t%u\t%c\t%u\t%u\n", 202f418815fSLars Ellenberg device->minor, device->vnr, 203f418815fSLars Ellenberg (flags & BM_AIO_READ) ? 'R' : 'W', 204f418815fSLars Ellenberg jiffies_to_msecs(now - start_jif), 205f418815fSLars Ellenberg in_flight); 206f418815fSLars Ellenberg } 207f418815fSLars Ellenberg } 208f418815fSLars Ellenberg 209f418815fSLars Ellenberg static void seq_print_resource_pending_bitmap_io(struct seq_file *m, struct drbd_resource *resource, unsigned long now) 210f418815fSLars Ellenberg { 211f418815fSLars Ellenberg struct drbd_device *device; 212f418815fSLars Ellenberg unsigned int i; 213f418815fSLars Ellenberg 214f418815fSLars Ellenberg seq_puts(m, "minor\tvnr\trw\tage\t#in-flight\n"); 215f418815fSLars Ellenberg rcu_read_lock(); 216f418815fSLars Ellenberg idr_for_each_entry(&resource->devices, device, i) { 217f418815fSLars Ellenberg seq_print_device_bitmap_io(m, device, now); 218f418815fSLars Ellenberg } 219f418815fSLars Ellenberg rcu_read_unlock(); 220f418815fSLars Ellenberg } 221f418815fSLars Ellenberg 222f418815fSLars Ellenberg /* pretty print enum peer_req->flags */ 223f418815fSLars Ellenberg static void seq_print_peer_request_flags(struct seq_file *m, struct drbd_peer_request *peer_req) 224f418815fSLars Ellenberg { 225f418815fSLars Ellenberg unsigned long f = peer_req->flags; 226f418815fSLars Ellenberg char sep = ' '; 227f418815fSLars Ellenberg 228f418815fSLars Ellenberg __seq_print_rq_state_bit(m, f & EE_SUBMITTED, &sep, "submitted", "preparing"); 229f418815fSLars Ellenberg __seq_print_rq_state_bit(m, f & EE_APPLICATION, &sep, "application", "internal"); 230f418815fSLars Ellenberg seq_print_rq_state_bit(m, f & EE_CALL_AL_COMPLETE_IO, &sep, "in-AL"); 231f418815fSLars Ellenberg seq_print_rq_state_bit(m, f & EE_SEND_WRITE_ACK, &sep, "C"); 232f418815fSLars Ellenberg seq_print_rq_state_bit(m, f & EE_MAY_SET_IN_SYNC, &sep, "set-in-sync"); 233f418815fSLars Ellenberg 234f418815fSLars Ellenberg if (f & EE_IS_TRIM) { 235f418815fSLars Ellenberg seq_putc(m, sep); 236f418815fSLars Ellenberg sep = '|'; 237f418815fSLars Ellenberg if (f & EE_IS_TRIM_USE_ZEROOUT) 238f418815fSLars Ellenberg seq_puts(m, "zero-out"); 239f418815fSLars Ellenberg else 240f418815fSLars Ellenberg seq_puts(m, "trim"); 241f418815fSLars Ellenberg } 242f418815fSLars Ellenberg seq_putc(m, '\n'); 243f418815fSLars Ellenberg } 244f418815fSLars Ellenberg 245f418815fSLars Ellenberg static void seq_print_peer_request(struct seq_file *m, 246f418815fSLars Ellenberg struct drbd_device *device, struct list_head *lh, 247f418815fSLars Ellenberg unsigned long now) 248f418815fSLars Ellenberg { 249f418815fSLars Ellenberg bool reported_preparing = false; 250f418815fSLars Ellenberg struct drbd_peer_request *peer_req; 251f418815fSLars Ellenberg list_for_each_entry(peer_req, lh, w.list) { 252f418815fSLars Ellenberg if (reported_preparing && !(peer_req->flags & EE_SUBMITTED)) 253f418815fSLars Ellenberg continue; 254f418815fSLars Ellenberg 255f418815fSLars Ellenberg if (device) 256f418815fSLars Ellenberg seq_printf(m, "%u\t%u\t", device->minor, device->vnr); 257f418815fSLars Ellenberg 258f418815fSLars Ellenberg seq_printf(m, "%llu\t%u\t%c\t%u\t", 259f418815fSLars Ellenberg (unsigned long long)peer_req->i.sector, peer_req->i.size >> 9, 260f418815fSLars Ellenberg (peer_req->flags & EE_WRITE) ? 'W' : 'R', 261f418815fSLars Ellenberg jiffies_to_msecs(now - peer_req->submit_jif)); 262f418815fSLars Ellenberg seq_print_peer_request_flags(m, peer_req); 263f418815fSLars Ellenberg if (peer_req->flags & EE_SUBMITTED) 264f418815fSLars Ellenberg break; 265f418815fSLars Ellenberg else 266f418815fSLars Ellenberg reported_preparing = true; 267f418815fSLars Ellenberg } 268f418815fSLars Ellenberg } 269f418815fSLars Ellenberg 270f418815fSLars Ellenberg static void seq_print_device_peer_requests(struct seq_file *m, 271f418815fSLars Ellenberg struct drbd_device *device, unsigned long now) 272f418815fSLars Ellenberg { 273f418815fSLars Ellenberg seq_puts(m, "minor\tvnr\tsector\tsize\trw\tage\tflags\n"); 274f418815fSLars Ellenberg spin_lock_irq(&device->resource->req_lock); 275f418815fSLars Ellenberg seq_print_peer_request(m, device, &device->active_ee, now); 276f418815fSLars Ellenberg seq_print_peer_request(m, device, &device->read_ee, now); 277f418815fSLars Ellenberg seq_print_peer_request(m, device, &device->sync_ee, now); 278f418815fSLars Ellenberg spin_unlock_irq(&device->resource->req_lock); 279f418815fSLars Ellenberg if (test_bit(FLUSH_PENDING, &device->flags)) { 280f418815fSLars Ellenberg seq_printf(m, "%u\t%u\t-\t-\tF\t%u\tflush\n", 281f418815fSLars Ellenberg device->minor, device->vnr, 282f418815fSLars Ellenberg jiffies_to_msecs(now - device->flush_jif)); 283f418815fSLars Ellenberg } 284f418815fSLars Ellenberg } 285f418815fSLars Ellenberg 286f418815fSLars Ellenberg static void seq_print_resource_pending_peer_requests(struct seq_file *m, 287f418815fSLars Ellenberg struct drbd_resource *resource, unsigned long now) 288f418815fSLars Ellenberg { 289f418815fSLars Ellenberg struct drbd_device *device; 290f418815fSLars Ellenberg unsigned int i; 291f418815fSLars Ellenberg 292f418815fSLars Ellenberg rcu_read_lock(); 293f418815fSLars Ellenberg idr_for_each_entry(&resource->devices, device, i) { 294f418815fSLars Ellenberg seq_print_device_peer_requests(m, device, now); 295f418815fSLars Ellenberg } 296f418815fSLars Ellenberg rcu_read_unlock(); 297f418815fSLars Ellenberg } 298f418815fSLars Ellenberg 299db1866ffSLars Ellenberg static void seq_print_resource_transfer_log_summary(struct seq_file *m, 300db1866ffSLars Ellenberg struct drbd_resource *resource, 301db1866ffSLars Ellenberg struct drbd_connection *connection, 302db1866ffSLars Ellenberg unsigned long now) 303db1866ffSLars Ellenberg { 304db1866ffSLars Ellenberg struct drbd_request *req; 305db1866ffSLars Ellenberg unsigned int count = 0; 306db1866ffSLars Ellenberg unsigned int show_state = 0; 307db1866ffSLars Ellenberg 308db1866ffSLars Ellenberg seq_puts(m, "n\tdevice\tvnr\t" RQ_HDR); 309db1866ffSLars Ellenberg spin_lock_irq(&resource->req_lock); 310db1866ffSLars Ellenberg list_for_each_entry(req, &connection->transfer_log, tl_requests) { 311db1866ffSLars Ellenberg unsigned int tmp = 0; 312db1866ffSLars Ellenberg unsigned int s; 313db1866ffSLars Ellenberg ++count; 314db1866ffSLars Ellenberg 315db1866ffSLars Ellenberg /* don't disable irq "forever" */ 316db1866ffSLars Ellenberg if (!(count & 0x1ff)) { 317db1866ffSLars Ellenberg struct drbd_request *req_next; 318db1866ffSLars Ellenberg kref_get(&req->kref); 319db1866ffSLars Ellenberg spin_unlock_irq(&resource->req_lock); 320db1866ffSLars Ellenberg cond_resched(); 321db1866ffSLars Ellenberg spin_lock_irq(&resource->req_lock); 322db1866ffSLars Ellenberg req_next = list_next_entry(req, tl_requests); 323db1866ffSLars Ellenberg if (kref_put(&req->kref, drbd_req_destroy)) 324db1866ffSLars Ellenberg req = req_next; 325db1866ffSLars Ellenberg if (&req->tl_requests == &connection->transfer_log) 326db1866ffSLars Ellenberg break; 327db1866ffSLars Ellenberg } 328db1866ffSLars Ellenberg 329db1866ffSLars Ellenberg s = req->rq_state; 330db1866ffSLars Ellenberg 331db1866ffSLars Ellenberg /* This is meant to summarize timing issues, to be able to tell 332db1866ffSLars Ellenberg * local disk problems from network problems. 333db1866ffSLars Ellenberg * Skip requests, if we have shown an even older request with 334db1866ffSLars Ellenberg * similar aspects already. */ 335db1866ffSLars Ellenberg if (req->master_bio == NULL) 336db1866ffSLars Ellenberg tmp |= 1; 337db1866ffSLars Ellenberg if ((s & RQ_LOCAL_MASK) && (s & RQ_LOCAL_PENDING)) 338db1866ffSLars Ellenberg tmp |= 2; 339db1866ffSLars Ellenberg if (s & RQ_NET_MASK) { 340db1866ffSLars Ellenberg if (!(s & RQ_NET_SENT)) 341db1866ffSLars Ellenberg tmp |= 4; 342db1866ffSLars Ellenberg if (s & RQ_NET_PENDING) 343db1866ffSLars Ellenberg tmp |= 8; 344db1866ffSLars Ellenberg if (!(s & RQ_NET_DONE)) 345db1866ffSLars Ellenberg tmp |= 16; 346db1866ffSLars Ellenberg } 347db1866ffSLars Ellenberg if ((tmp & show_state) == tmp) 348db1866ffSLars Ellenberg continue; 349db1866ffSLars Ellenberg show_state |= tmp; 350db1866ffSLars Ellenberg seq_printf(m, "%u\t", count); 351db1866ffSLars Ellenberg seq_print_minor_vnr_req(m, req, now); 352db1866ffSLars Ellenberg if (show_state == 0x1f) 353db1866ffSLars Ellenberg break; 354db1866ffSLars Ellenberg } 355db1866ffSLars Ellenberg spin_unlock_irq(&resource->req_lock); 356db1866ffSLars Ellenberg } 357db1866ffSLars Ellenberg 358db1866ffSLars Ellenberg /* TODO: transfer_log and friends should be moved to resource */ 359db1866ffSLars Ellenberg static int in_flight_summary_show(struct seq_file *m, void *pos) 360db1866ffSLars Ellenberg { 361db1866ffSLars Ellenberg struct drbd_resource *resource = m->private; 362db1866ffSLars Ellenberg struct drbd_connection *connection; 363db1866ffSLars Ellenberg unsigned long jif = jiffies; 364db1866ffSLars Ellenberg 365db1866ffSLars Ellenberg connection = first_connection(resource); 366db1866ffSLars Ellenberg /* This does not happen, actually. 367db1866ffSLars Ellenberg * But be robust and prepare for future code changes. */ 3684a521ccaSLars Ellenberg if (!connection || !kref_get_unless_zero(&connection->kref)) 3694a521ccaSLars Ellenberg return -ESTALE; 370db1866ffSLars Ellenberg 371f418815fSLars Ellenberg seq_puts(m, "oldest bitmap IO\n"); 372f418815fSLars Ellenberg seq_print_resource_pending_bitmap_io(m, resource, jif); 373f418815fSLars Ellenberg seq_putc(m, '\n'); 374f418815fSLars Ellenberg 375f418815fSLars Ellenberg seq_puts(m, "meta data IO\n"); 376f418815fSLars Ellenberg seq_print_resource_pending_meta_io(m, resource, jif); 377f418815fSLars Ellenberg seq_putc(m, '\n'); 378f418815fSLars Ellenberg 379f418815fSLars Ellenberg seq_puts(m, "socket buffer stats\n"); 380f418815fSLars Ellenberg /* for each connection ... once we have more than one */ 381f418815fSLars Ellenberg rcu_read_lock(); 382f418815fSLars Ellenberg if (connection->data.socket) { 383f418815fSLars Ellenberg /* open coded SIOCINQ, the "relevant" part */ 384f418815fSLars Ellenberg struct tcp_sock *tp = tcp_sk(connection->data.socket->sk); 385f418815fSLars Ellenberg int answ = tp->rcv_nxt - tp->copied_seq; 386f418815fSLars Ellenberg seq_printf(m, "unread receive buffer: %u Byte\n", answ); 387f418815fSLars Ellenberg /* open coded SIOCOUTQ, the "relevant" part */ 388f418815fSLars Ellenberg answ = tp->write_seq - tp->snd_una; 389f418815fSLars Ellenberg seq_printf(m, "unacked send buffer: %u Byte\n", answ); 390f418815fSLars Ellenberg } 391f418815fSLars Ellenberg rcu_read_unlock(); 392f418815fSLars Ellenberg seq_putc(m, '\n'); 393f418815fSLars Ellenberg 394f418815fSLars Ellenberg seq_puts(m, "oldest peer requests\n"); 395f418815fSLars Ellenberg seq_print_resource_pending_peer_requests(m, resource, jif); 396f418815fSLars Ellenberg seq_putc(m, '\n'); 397f418815fSLars Ellenberg 398f418815fSLars Ellenberg seq_puts(m, "application requests waiting for activity log\n"); 399f418815fSLars Ellenberg seq_print_waiting_for_AL(m, resource, jif); 400f418815fSLars Ellenberg seq_putc(m, '\n'); 401f418815fSLars Ellenberg 402db1866ffSLars Ellenberg seq_puts(m, "oldest application requests\n"); 403db1866ffSLars Ellenberg seq_print_resource_transfer_log_summary(m, resource, connection, jif); 404db1866ffSLars Ellenberg seq_putc(m, '\n'); 405db1866ffSLars Ellenberg 406db1866ffSLars Ellenberg jif = jiffies - jif; 407db1866ffSLars Ellenberg if (jif) 408db1866ffSLars Ellenberg seq_printf(m, "generated in %d ms\n", jiffies_to_msecs(jif)); 4094a521ccaSLars Ellenberg kref_put(&connection->kref, drbd_destroy_connection); 410db1866ffSLars Ellenberg return 0; 411db1866ffSLars Ellenberg } 412db1866ffSLars Ellenberg 4134a521ccaSLars Ellenberg /* simple_positive(file->f_dentry) respectively debugfs_positive(), 4144a521ccaSLars Ellenberg * but neither is "reachable" from here. 4154a521ccaSLars Ellenberg * So we have our own inline version of it above. :-( */ 4164a521ccaSLars Ellenberg static inline int debugfs_positive(struct dentry *dentry) 4174a521ccaSLars Ellenberg { 4184a521ccaSLars Ellenberg return dentry->d_inode && !d_unhashed(dentry); 4194a521ccaSLars Ellenberg } 4204a521ccaSLars Ellenberg 4214a521ccaSLars Ellenberg /* make sure at *open* time that the respective object won't go away. */ 4224a521ccaSLars Ellenberg static int drbd_single_open(struct file *file, int (*show)(struct seq_file *, void *), 4234a521ccaSLars Ellenberg void *data, struct kref *kref, 4244a521ccaSLars Ellenberg void (*release)(struct kref *)) 4254a521ccaSLars Ellenberg { 4264a521ccaSLars Ellenberg struct dentry *parent; 4274a521ccaSLars Ellenberg int ret = -ESTALE; 4284a521ccaSLars Ellenberg 4294a521ccaSLars Ellenberg /* Are we still linked, 4304a521ccaSLars Ellenberg * or has debugfs_remove() already been called? */ 4314a521ccaSLars Ellenberg parent = file->f_dentry->d_parent; 4324a521ccaSLars Ellenberg /* not sure if this can happen: */ 4334a521ccaSLars Ellenberg if (!parent || !parent->d_inode) 4344a521ccaSLars Ellenberg goto out; 4354a521ccaSLars Ellenberg /* serialize with d_delete() */ 4364a521ccaSLars Ellenberg mutex_lock(&parent->d_inode->i_mutex); 4374a521ccaSLars Ellenberg if (!debugfs_positive(file->f_dentry)) 4384a521ccaSLars Ellenberg goto out_unlock; 4394a521ccaSLars Ellenberg /* Make sure the object is still alive */ 4404a521ccaSLars Ellenberg if (kref_get_unless_zero(kref)) 4414a521ccaSLars Ellenberg ret = 0; 4424a521ccaSLars Ellenberg out_unlock: 4434a521ccaSLars Ellenberg mutex_unlock(&parent->d_inode->i_mutex); 4444a521ccaSLars Ellenberg if (!ret) { 4454a521ccaSLars Ellenberg ret = single_open(file, show, data); 4464a521ccaSLars Ellenberg if (ret) 4474a521ccaSLars Ellenberg kref_put(kref, release); 4484a521ccaSLars Ellenberg } 4494a521ccaSLars Ellenberg out: 4504a521ccaSLars Ellenberg return ret; 4514a521ccaSLars Ellenberg } 4524a521ccaSLars Ellenberg 453db1866ffSLars Ellenberg static int in_flight_summary_open(struct inode *inode, struct file *file) 454db1866ffSLars Ellenberg { 4554a521ccaSLars Ellenberg struct drbd_resource *resource = inode->i_private; 4564a521ccaSLars Ellenberg return drbd_single_open(file, in_flight_summary_show, resource, 4574a521ccaSLars Ellenberg &resource->kref, drbd_destroy_resource); 4584a521ccaSLars Ellenberg } 4594a521ccaSLars Ellenberg 4604a521ccaSLars Ellenberg static int in_flight_summary_release(struct inode *inode, struct file *file) 4614a521ccaSLars Ellenberg { 4624a521ccaSLars Ellenberg struct drbd_resource *resource = inode->i_private; 4634a521ccaSLars Ellenberg kref_put(&resource->kref, drbd_destroy_resource); 4644a521ccaSLars Ellenberg return single_release(inode, file); 465db1866ffSLars Ellenberg } 466db1866ffSLars Ellenberg 467db1866ffSLars Ellenberg static const struct file_operations in_flight_summary_fops = { 468db1866ffSLars Ellenberg .owner = THIS_MODULE, 469db1866ffSLars Ellenberg .open = in_flight_summary_open, 470db1866ffSLars Ellenberg .read = seq_read, 471db1866ffSLars Ellenberg .llseek = seq_lseek, 4724a521ccaSLars Ellenberg .release = in_flight_summary_release, 473db1866ffSLars Ellenberg }; 474db1866ffSLars Ellenberg 4754d3d5aa8SLars Ellenberg void drbd_debugfs_resource_add(struct drbd_resource *resource) 4764d3d5aa8SLars Ellenberg { 4774d3d5aa8SLars Ellenberg struct dentry *dentry; 4784d3d5aa8SLars Ellenberg if (!drbd_debugfs_resources) 4794d3d5aa8SLars Ellenberg return; 4804d3d5aa8SLars Ellenberg 4814d3d5aa8SLars Ellenberg dentry = debugfs_create_dir(resource->name, drbd_debugfs_resources); 4824d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 4834d3d5aa8SLars Ellenberg goto fail; 4844d3d5aa8SLars Ellenberg resource->debugfs_res = dentry; 4854d3d5aa8SLars Ellenberg 4864d3d5aa8SLars Ellenberg dentry = debugfs_create_dir("volumes", resource->debugfs_res); 4874d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 4884d3d5aa8SLars Ellenberg goto fail; 4894d3d5aa8SLars Ellenberg resource->debugfs_res_volumes = dentry; 4904d3d5aa8SLars Ellenberg 4914d3d5aa8SLars Ellenberg dentry = debugfs_create_dir("connections", resource->debugfs_res); 4924d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 4934d3d5aa8SLars Ellenberg goto fail; 4944d3d5aa8SLars Ellenberg resource->debugfs_res_connections = dentry; 4954d3d5aa8SLars Ellenberg 496db1866ffSLars Ellenberg dentry = debugfs_create_file("in_flight_summary", S_IRUSR|S_IRGRP, 497db1866ffSLars Ellenberg resource->debugfs_res, resource, 498db1866ffSLars Ellenberg &in_flight_summary_fops); 499db1866ffSLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 500db1866ffSLars Ellenberg goto fail; 501db1866ffSLars Ellenberg resource->debugfs_res_in_flight_summary = dentry; 5024d3d5aa8SLars Ellenberg return; 5034d3d5aa8SLars Ellenberg 5044d3d5aa8SLars Ellenberg fail: 5054d3d5aa8SLars Ellenberg drbd_debugfs_resource_cleanup(resource); 5064d3d5aa8SLars Ellenberg drbd_err(resource, "failed to create debugfs dentry\n"); 5074d3d5aa8SLars Ellenberg } 5084d3d5aa8SLars Ellenberg 5094d3d5aa8SLars Ellenberg static void drbd_debugfs_remove(struct dentry **dp) 5104d3d5aa8SLars Ellenberg { 5114d3d5aa8SLars Ellenberg debugfs_remove(*dp); 5124d3d5aa8SLars Ellenberg *dp = NULL; 5134d3d5aa8SLars Ellenberg } 5144d3d5aa8SLars Ellenberg 5154d3d5aa8SLars Ellenberg void drbd_debugfs_resource_cleanup(struct drbd_resource *resource) 5164d3d5aa8SLars Ellenberg { 5174d3d5aa8SLars Ellenberg /* it is ok to call debugfs_remove(NULL) */ 5184d3d5aa8SLars Ellenberg drbd_debugfs_remove(&resource->debugfs_res_in_flight_summary); 5194d3d5aa8SLars Ellenberg drbd_debugfs_remove(&resource->debugfs_res_connections); 5204d3d5aa8SLars Ellenberg drbd_debugfs_remove(&resource->debugfs_res_volumes); 5214d3d5aa8SLars Ellenberg drbd_debugfs_remove(&resource->debugfs_res); 5224d3d5aa8SLars Ellenberg } 5234d3d5aa8SLars Ellenberg 524*944410e9SLars Ellenberg static void seq_print_one_timing_detail(struct seq_file *m, 525*944410e9SLars Ellenberg const struct drbd_thread_timing_details *tdp, 526*944410e9SLars Ellenberg unsigned long now) 527*944410e9SLars Ellenberg { 528*944410e9SLars Ellenberg struct drbd_thread_timing_details td; 529*944410e9SLars Ellenberg /* No locking... 530*944410e9SLars Ellenberg * use temporary assignment to get at consistent data. */ 531*944410e9SLars Ellenberg do { 532*944410e9SLars Ellenberg td = *tdp; 533*944410e9SLars Ellenberg } while (td.cb_nr != tdp->cb_nr); 534*944410e9SLars Ellenberg if (!td.cb_addr) 535*944410e9SLars Ellenberg return; 536*944410e9SLars Ellenberg seq_printf(m, "%u\t%d\t%s:%u\t%ps\n", 537*944410e9SLars Ellenberg td.cb_nr, 538*944410e9SLars Ellenberg jiffies_to_msecs(now - td.start_jif), 539*944410e9SLars Ellenberg td.caller_fn, td.line, 540*944410e9SLars Ellenberg td.cb_addr); 541*944410e9SLars Ellenberg } 542*944410e9SLars Ellenberg 543*944410e9SLars Ellenberg static void seq_print_timing_details(struct seq_file *m, 544*944410e9SLars Ellenberg const char *title, 545*944410e9SLars Ellenberg unsigned int cb_nr, struct drbd_thread_timing_details *tdp, unsigned long now) 546*944410e9SLars Ellenberg { 547*944410e9SLars Ellenberg unsigned int start_idx; 548*944410e9SLars Ellenberg unsigned int i; 549*944410e9SLars Ellenberg 550*944410e9SLars Ellenberg seq_printf(m, "%s\n", title); 551*944410e9SLars Ellenberg /* If not much is going on, this will result in natural ordering. 552*944410e9SLars Ellenberg * If it is very busy, we will possibly skip events, or even see wrap 553*944410e9SLars Ellenberg * arounds, which could only be avoided with locking. 554*944410e9SLars Ellenberg */ 555*944410e9SLars Ellenberg start_idx = cb_nr % DRBD_THREAD_DETAILS_HIST; 556*944410e9SLars Ellenberg for (i = start_idx; i < DRBD_THREAD_DETAILS_HIST; i++) 557*944410e9SLars Ellenberg seq_print_one_timing_detail(m, tdp+i, now); 558*944410e9SLars Ellenberg for (i = 0; i < start_idx; i++) 559*944410e9SLars Ellenberg seq_print_one_timing_detail(m, tdp+i, now); 560*944410e9SLars Ellenberg } 561*944410e9SLars Ellenberg 562*944410e9SLars Ellenberg static int callback_history_show(struct seq_file *m, void *ignored) 563*944410e9SLars Ellenberg { 564*944410e9SLars Ellenberg struct drbd_connection *connection = m->private; 565*944410e9SLars Ellenberg unsigned long jif = jiffies; 566*944410e9SLars Ellenberg 567*944410e9SLars Ellenberg seq_puts(m, "n\tage\tcallsite\tfn\n"); 568*944410e9SLars Ellenberg seq_print_timing_details(m, "worker", connection->w_cb_nr, connection->w_timing_details, jif); 569*944410e9SLars Ellenberg seq_print_timing_details(m, "receiver", connection->r_cb_nr, connection->r_timing_details, jif); 570*944410e9SLars Ellenberg return 0; 571*944410e9SLars Ellenberg } 572*944410e9SLars Ellenberg 573*944410e9SLars Ellenberg static int callback_history_open(struct inode *inode, struct file *file) 574*944410e9SLars Ellenberg { 575*944410e9SLars Ellenberg struct drbd_connection *connection = inode->i_private; 576*944410e9SLars Ellenberg return drbd_single_open(file, callback_history_show, connection, 577*944410e9SLars Ellenberg &connection->kref, drbd_destroy_connection); 578*944410e9SLars Ellenberg } 579*944410e9SLars Ellenberg 580*944410e9SLars Ellenberg static int callback_history_release(struct inode *inode, struct file *file) 581*944410e9SLars Ellenberg { 582*944410e9SLars Ellenberg struct drbd_connection *connection = inode->i_private; 583*944410e9SLars Ellenberg kref_put(&connection->kref, drbd_destroy_connection); 584*944410e9SLars Ellenberg return single_release(inode, file); 585*944410e9SLars Ellenberg } 586*944410e9SLars Ellenberg 587*944410e9SLars Ellenberg static const struct file_operations connection_callback_history_fops = { 588*944410e9SLars Ellenberg .owner = THIS_MODULE, 589*944410e9SLars Ellenberg .open = callback_history_open, 590*944410e9SLars Ellenberg .read = seq_read, 591*944410e9SLars Ellenberg .llseek = seq_lseek, 592*944410e9SLars Ellenberg .release = callback_history_release, 593*944410e9SLars Ellenberg }; 594*944410e9SLars Ellenberg 5954d3d5aa8SLars Ellenberg void drbd_debugfs_connection_add(struct drbd_connection *connection) 5964d3d5aa8SLars Ellenberg { 5974d3d5aa8SLars Ellenberg struct dentry *conns_dir = connection->resource->debugfs_res_connections; 5984d3d5aa8SLars Ellenberg struct dentry *dentry; 5994d3d5aa8SLars Ellenberg if (!conns_dir) 6004d3d5aa8SLars Ellenberg return; 6014d3d5aa8SLars Ellenberg 6024d3d5aa8SLars Ellenberg /* Once we enable mutliple peers, 6034d3d5aa8SLars Ellenberg * these connections will have descriptive names. 6044d3d5aa8SLars Ellenberg * For now, it is just the one connection to the (only) "peer". */ 6054d3d5aa8SLars Ellenberg dentry = debugfs_create_dir("peer", conns_dir); 6064d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 6074d3d5aa8SLars Ellenberg goto fail; 6084d3d5aa8SLars Ellenberg connection->debugfs_conn = dentry; 609*944410e9SLars Ellenberg 610*944410e9SLars Ellenberg dentry = debugfs_create_file("callback_history", S_IRUSR|S_IRGRP, 611*944410e9SLars Ellenberg connection->debugfs_conn, connection, 612*944410e9SLars Ellenberg &connection_callback_history_fops); 613*944410e9SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 614*944410e9SLars Ellenberg goto fail; 615*944410e9SLars Ellenberg connection->debugfs_conn_callback_history = dentry; 6164d3d5aa8SLars Ellenberg return; 6174d3d5aa8SLars Ellenberg 6184d3d5aa8SLars Ellenberg fail: 6194d3d5aa8SLars Ellenberg drbd_debugfs_connection_cleanup(connection); 6204d3d5aa8SLars Ellenberg drbd_err(connection, "failed to create debugfs dentry\n"); 6214d3d5aa8SLars Ellenberg } 6224d3d5aa8SLars Ellenberg 6234d3d5aa8SLars Ellenberg void drbd_debugfs_connection_cleanup(struct drbd_connection *connection) 6244d3d5aa8SLars Ellenberg { 6254d3d5aa8SLars Ellenberg drbd_debugfs_remove(&connection->debugfs_conn_callback_history); 6264d3d5aa8SLars Ellenberg drbd_debugfs_remove(&connection->debugfs_conn_oldest_requests); 6274d3d5aa8SLars Ellenberg drbd_debugfs_remove(&connection->debugfs_conn); 6284d3d5aa8SLars Ellenberg } 6294d3d5aa8SLars Ellenberg 6304d3d5aa8SLars Ellenberg void drbd_debugfs_device_add(struct drbd_device *device) 6314d3d5aa8SLars Ellenberg { 6324d3d5aa8SLars Ellenberg struct dentry *vols_dir = device->resource->debugfs_res_volumes; 6334d3d5aa8SLars Ellenberg char minor_buf[8]; /* MINORMASK, MINORBITS == 20; */ 6344d3d5aa8SLars Ellenberg char vnr_buf[8]; /* volume number vnr is even 16 bit only; */ 6354d3d5aa8SLars Ellenberg char *slink_name = NULL; 6364d3d5aa8SLars Ellenberg 6374d3d5aa8SLars Ellenberg struct dentry *dentry; 6384d3d5aa8SLars Ellenberg if (!vols_dir || !drbd_debugfs_minors) 6394d3d5aa8SLars Ellenberg return; 6404d3d5aa8SLars Ellenberg 6414d3d5aa8SLars Ellenberg snprintf(vnr_buf, sizeof(vnr_buf), "%u", device->vnr); 6424d3d5aa8SLars Ellenberg dentry = debugfs_create_dir(vnr_buf, vols_dir); 6434d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 6444d3d5aa8SLars Ellenberg goto fail; 6454d3d5aa8SLars Ellenberg device->debugfs_vol = dentry; 6464d3d5aa8SLars Ellenberg 6474d3d5aa8SLars Ellenberg snprintf(minor_buf, sizeof(minor_buf), "%u", device->minor); 6484d3d5aa8SLars Ellenberg slink_name = kasprintf(GFP_KERNEL, "../resources/%s/volumes/%u", 6494d3d5aa8SLars Ellenberg device->resource->name, device->vnr); 6504d3d5aa8SLars Ellenberg if (!slink_name) 6514d3d5aa8SLars Ellenberg goto fail; 6524d3d5aa8SLars Ellenberg dentry = debugfs_create_symlink(minor_buf, drbd_debugfs_minors, slink_name); 6534d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 6544d3d5aa8SLars Ellenberg goto fail; 6554d3d5aa8SLars Ellenberg device->debugfs_minor = dentry; 6564d3d5aa8SLars Ellenberg kfree(slink_name); 6574d3d5aa8SLars Ellenberg 6584d3d5aa8SLars Ellenberg fail: 6594d3d5aa8SLars Ellenberg drbd_debugfs_device_cleanup(device); 6604d3d5aa8SLars Ellenberg drbd_err(device, "failed to create debugfs entries\n"); 6614d3d5aa8SLars Ellenberg } 6624d3d5aa8SLars Ellenberg 6634d3d5aa8SLars Ellenberg void drbd_debugfs_device_cleanup(struct drbd_device *device) 6644d3d5aa8SLars Ellenberg { 6654d3d5aa8SLars Ellenberg drbd_debugfs_remove(&device->debugfs_minor); 6664d3d5aa8SLars Ellenberg drbd_debugfs_remove(&device->debugfs_vol_oldest_requests); 6674d3d5aa8SLars Ellenberg drbd_debugfs_remove(&device->debugfs_vol_act_log_extents); 6684d3d5aa8SLars Ellenberg drbd_debugfs_remove(&device->debugfs_vol_resync_extents); 6694d3d5aa8SLars Ellenberg drbd_debugfs_remove(&device->debugfs_vol_data_gen_id); 6704d3d5aa8SLars Ellenberg drbd_debugfs_remove(&device->debugfs_vol); 6714d3d5aa8SLars Ellenberg } 6724d3d5aa8SLars Ellenberg 6734d3d5aa8SLars Ellenberg void drbd_debugfs_peer_device_add(struct drbd_peer_device *peer_device) 6744d3d5aa8SLars Ellenberg { 6754d3d5aa8SLars Ellenberg struct dentry *conn_dir = peer_device->connection->debugfs_conn; 6764d3d5aa8SLars Ellenberg struct dentry *dentry; 6774d3d5aa8SLars Ellenberg char vnr_buf[8]; 6784d3d5aa8SLars Ellenberg 6794d3d5aa8SLars Ellenberg if (!conn_dir) 6804d3d5aa8SLars Ellenberg return; 6814d3d5aa8SLars Ellenberg 6824d3d5aa8SLars Ellenberg snprintf(vnr_buf, sizeof(vnr_buf), "%u", peer_device->device->vnr); 6834d3d5aa8SLars Ellenberg dentry = debugfs_create_dir(vnr_buf, conn_dir); 6844d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 6854d3d5aa8SLars Ellenberg goto fail; 6864d3d5aa8SLars Ellenberg peer_device->debugfs_peer_dev = dentry; 6874d3d5aa8SLars Ellenberg return; 6884d3d5aa8SLars Ellenberg 6894d3d5aa8SLars Ellenberg fail: 6904d3d5aa8SLars Ellenberg drbd_debugfs_peer_device_cleanup(peer_device); 6914d3d5aa8SLars Ellenberg drbd_err(peer_device, "failed to create debugfs entries\n"); 6924d3d5aa8SLars Ellenberg } 6934d3d5aa8SLars Ellenberg 6944d3d5aa8SLars Ellenberg void drbd_debugfs_peer_device_cleanup(struct drbd_peer_device *peer_device) 6954d3d5aa8SLars Ellenberg { 6964d3d5aa8SLars Ellenberg drbd_debugfs_remove(&peer_device->debugfs_peer_dev); 6974d3d5aa8SLars Ellenberg } 6984d3d5aa8SLars Ellenberg 6994d3d5aa8SLars Ellenberg /* not __exit, may be indirectly called 7004d3d5aa8SLars Ellenberg * from the module-load-failure path as well. */ 7014d3d5aa8SLars Ellenberg void drbd_debugfs_cleanup(void) 7024d3d5aa8SLars Ellenberg { 7034d3d5aa8SLars Ellenberg drbd_debugfs_remove(&drbd_debugfs_resources); 7044d3d5aa8SLars Ellenberg drbd_debugfs_remove(&drbd_debugfs_minors); 7054d3d5aa8SLars Ellenberg drbd_debugfs_remove(&drbd_debugfs_root); 7064d3d5aa8SLars Ellenberg } 7074d3d5aa8SLars Ellenberg 7084d3d5aa8SLars Ellenberg int __init drbd_debugfs_init(void) 7094d3d5aa8SLars Ellenberg { 7104d3d5aa8SLars Ellenberg struct dentry *dentry; 7114d3d5aa8SLars Ellenberg 7124d3d5aa8SLars Ellenberg dentry = debugfs_create_dir("drbd", NULL); 7134d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 7144d3d5aa8SLars Ellenberg goto fail; 7154d3d5aa8SLars Ellenberg drbd_debugfs_root = dentry; 7164d3d5aa8SLars Ellenberg 7174d3d5aa8SLars Ellenberg dentry = debugfs_create_dir("resources", drbd_debugfs_root); 7184d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 7194d3d5aa8SLars Ellenberg goto fail; 7204d3d5aa8SLars Ellenberg drbd_debugfs_resources = dentry; 7214d3d5aa8SLars Ellenberg 7224d3d5aa8SLars Ellenberg dentry = debugfs_create_dir("minors", drbd_debugfs_root); 7234d3d5aa8SLars Ellenberg if (IS_ERR_OR_NULL(dentry)) 7244d3d5aa8SLars Ellenberg goto fail; 7254d3d5aa8SLars Ellenberg drbd_debugfs_minors = dentry; 7264d3d5aa8SLars Ellenberg return 0; 7274d3d5aa8SLars Ellenberg 7284d3d5aa8SLars Ellenberg fail: 7294d3d5aa8SLars Ellenberg drbd_debugfs_cleanup(); 7304d3d5aa8SLars Ellenberg if (dentry) 7314d3d5aa8SLars Ellenberg return PTR_ERR(dentry); 7324d3d5aa8SLars Ellenberg else 7334d3d5aa8SLars Ellenberg return -EINVAL; 7344d3d5aa8SLars Ellenberg } 735