Merge branch 'drm-nouveau-fixes-3.9' of git://anongit.freedesktop.org/git/nouveau...
[linux-2.6/libata-dev.git] / fs / nfs / objlayout / objlayout.c
bloba9ebd817278b7beb301c222cb3e7abd1c183c3b4
1 /*
2 * pNFS Objects layout driver high level definitions
4 * Copyright (C) 2007 Panasas Inc. [year of first publication]
5 * All rights reserved.
7 * Benny Halevy <bhalevy@panasas.com>
8 * Boaz Harrosh <bharrosh@panasas.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * See the file COPYING included with this distribution for more details.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of the Panasas company nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
28 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
34 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <linux/kmod.h>
41 #include <linux/moduleparam.h>
42 #include <linux/ratelimit.h>
43 #include <scsi/osd_initiator.h>
44 #include "objlayout.h"
46 #define NFSDBG_FACILITY NFSDBG_PNFS_LD
48 * Create a objlayout layout structure for the given inode and return it.
50 struct pnfs_layout_hdr *
51 objlayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
53 struct objlayout *objlay;
55 objlay = kzalloc(sizeof(struct objlayout), gfp_flags);
56 if (objlay) {
57 spin_lock_init(&objlay->lock);
58 INIT_LIST_HEAD(&objlay->err_list);
60 dprintk("%s: Return %p\n", __func__, objlay);
61 return &objlay->pnfs_layout;
65 * Free an objlayout layout structure
67 void
68 objlayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
70 struct objlayout *objlay = OBJLAYOUT(lo);
72 dprintk("%s: objlay %p\n", __func__, objlay);
74 WARN_ON(!list_empty(&objlay->err_list));
75 kfree(objlay);
79 * Unmarshall layout and store it in pnfslay.
81 struct pnfs_layout_segment *
82 objlayout_alloc_lseg(struct pnfs_layout_hdr *pnfslay,
83 struct nfs4_layoutget_res *lgr,
84 gfp_t gfp_flags)
86 int status = -ENOMEM;
87 struct xdr_stream stream;
88 struct xdr_buf buf = {
89 .pages = lgr->layoutp->pages,
90 .page_len = lgr->layoutp->len,
91 .buflen = lgr->layoutp->len,
92 .len = lgr->layoutp->len,
94 struct page *scratch;
95 struct pnfs_layout_segment *lseg;
97 dprintk("%s: Begin pnfslay %p\n", __func__, pnfslay);
99 scratch = alloc_page(gfp_flags);
100 if (!scratch)
101 goto err_nofree;
103 xdr_init_decode(&stream, &buf, NULL);
104 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
106 status = objio_alloc_lseg(&lseg, pnfslay, &lgr->range, &stream, gfp_flags);
107 if (unlikely(status)) {
108 dprintk("%s: objio_alloc_lseg Return err %d\n", __func__,
109 status);
110 goto err;
113 __free_page(scratch);
115 dprintk("%s: Return %p\n", __func__, lseg);
116 return lseg;
118 err:
119 __free_page(scratch);
120 err_nofree:
121 dprintk("%s: Err Return=>%d\n", __func__, status);
122 return ERR_PTR(status);
126 * Free a layout segement
128 void
129 objlayout_free_lseg(struct pnfs_layout_segment *lseg)
131 dprintk("%s: freeing layout segment %p\n", __func__, lseg);
133 if (unlikely(!lseg))
134 return;
136 objio_free_lseg(lseg);
140 * I/O Operations
142 static inline u64
143 end_offset(u64 start, u64 len)
145 u64 end;
147 end = start + len;
148 return end >= start ? end : NFS4_MAX_UINT64;
151 static void _fix_verify_io_params(struct pnfs_layout_segment *lseg,
152 struct page ***p_pages, unsigned *p_pgbase,
153 u64 offset, unsigned long count)
155 u64 lseg_end_offset;
157 BUG_ON(offset < lseg->pls_range.offset);
158 lseg_end_offset = end_offset(lseg->pls_range.offset,
159 lseg->pls_range.length);
160 BUG_ON(offset >= lseg_end_offset);
161 WARN_ON(offset + count > lseg_end_offset);
163 if (*p_pgbase > PAGE_SIZE) {
164 dprintk("%s: pgbase(0x%x) > PAGE_SIZE\n", __func__, *p_pgbase);
165 *p_pages += *p_pgbase >> PAGE_SHIFT;
166 *p_pgbase &= ~PAGE_MASK;
171 * I/O done common code
173 static void
174 objlayout_iodone(struct objlayout_io_res *oir)
176 if (likely(oir->status >= 0)) {
177 objio_free_result(oir);
178 } else {
179 struct objlayout *objlay = oir->objlay;
181 spin_lock(&objlay->lock);
182 objlay->delta_space_valid = OBJ_DSU_INVALID;
183 list_add(&objlay->err_list, &oir->err_list);
184 spin_unlock(&objlay->lock);
189 * objlayout_io_set_result - Set an osd_error code on a specific osd comp.
191 * The @index component IO failed (error returned from target). Register
192 * the error for later reporting at layout-return.
194 void
195 objlayout_io_set_result(struct objlayout_io_res *oir, unsigned index,
196 struct pnfs_osd_objid *pooid, int osd_error,
197 u64 offset, u64 length, bool is_write)
199 struct pnfs_osd_ioerr *ioerr = &oir->ioerrs[index];
201 BUG_ON(index >= oir->num_comps);
202 if (osd_error) {
203 ioerr->oer_component = *pooid;
204 ioerr->oer_comp_offset = offset;
205 ioerr->oer_comp_length = length;
206 ioerr->oer_iswrite = is_write;
207 ioerr->oer_errno = osd_error;
209 dprintk("%s: err[%d]: errno=%d is_write=%d dev(%llx:%llx) "
210 "par=0x%llx obj=0x%llx offset=0x%llx length=0x%llx\n",
211 __func__, index, ioerr->oer_errno,
212 ioerr->oer_iswrite,
213 _DEVID_LO(&ioerr->oer_component.oid_device_id),
214 _DEVID_HI(&ioerr->oer_component.oid_device_id),
215 ioerr->oer_component.oid_partition_id,
216 ioerr->oer_component.oid_object_id,
217 ioerr->oer_comp_offset,
218 ioerr->oer_comp_length);
219 } else {
220 /* User need not call if no error is reported */
221 ioerr->oer_errno = 0;
225 /* Function scheduled on rpc workqueue to call ->nfs_readlist_complete().
226 * This is because the osd completion is called with ints-off from
227 * the block layer
229 static void _rpc_read_complete(struct work_struct *work)
231 struct rpc_task *task;
232 struct nfs_read_data *rdata;
234 dprintk("%s enter\n", __func__);
235 task = container_of(work, struct rpc_task, u.tk_work);
236 rdata = container_of(task, struct nfs_read_data, task);
238 pnfs_ld_read_done(rdata);
241 void
242 objlayout_read_done(struct objlayout_io_res *oir, ssize_t status, bool sync)
244 struct nfs_read_data *rdata = oir->rpcdata;
246 oir->status = rdata->task.tk_status = status;
247 if (status >= 0)
248 rdata->res.count = status;
249 else
250 rdata->header->pnfs_error = status;
251 objlayout_iodone(oir);
252 /* must not use oir after this point */
254 dprintk("%s: Return status=%zd eof=%d sync=%d\n", __func__,
255 status, rdata->res.eof, sync);
257 if (sync)
258 pnfs_ld_read_done(rdata);
259 else {
260 INIT_WORK(&rdata->task.u.tk_work, _rpc_read_complete);
261 schedule_work(&rdata->task.u.tk_work);
266 * Perform sync or async reads.
268 enum pnfs_try_status
269 objlayout_read_pagelist(struct nfs_read_data *rdata)
271 struct nfs_pgio_header *hdr = rdata->header;
272 struct inode *inode = hdr->inode;
273 loff_t offset = rdata->args.offset;
274 size_t count = rdata->args.count;
275 int err;
276 loff_t eof;
278 eof = i_size_read(inode);
279 if (unlikely(offset + count > eof)) {
280 if (offset >= eof) {
281 err = 0;
282 rdata->res.count = 0;
283 rdata->res.eof = 1;
284 /*FIXME: do we need to call pnfs_ld_read_done() */
285 goto out;
287 count = eof - offset;
290 rdata->res.eof = (offset + count) >= eof;
291 _fix_verify_io_params(hdr->lseg, &rdata->args.pages,
292 &rdata->args.pgbase,
293 rdata->args.offset, rdata->args.count);
295 dprintk("%s: inode(%lx) offset 0x%llx count 0x%Zx eof=%d\n",
296 __func__, inode->i_ino, offset, count, rdata->res.eof);
298 err = objio_read_pagelist(rdata);
299 out:
300 if (unlikely(err)) {
301 hdr->pnfs_error = err;
302 dprintk("%s: Returned Error %d\n", __func__, err);
303 return PNFS_NOT_ATTEMPTED;
305 return PNFS_ATTEMPTED;
308 /* Function scheduled on rpc workqueue to call ->nfs_writelist_complete().
309 * This is because the osd completion is called with ints-off from
310 * the block layer
312 static void _rpc_write_complete(struct work_struct *work)
314 struct rpc_task *task;
315 struct nfs_write_data *wdata;
317 dprintk("%s enter\n", __func__);
318 task = container_of(work, struct rpc_task, u.tk_work);
319 wdata = container_of(task, struct nfs_write_data, task);
321 pnfs_ld_write_done(wdata);
324 void
325 objlayout_write_done(struct objlayout_io_res *oir, ssize_t status, bool sync)
327 struct nfs_write_data *wdata = oir->rpcdata;
329 oir->status = wdata->task.tk_status = status;
330 if (status >= 0) {
331 wdata->res.count = status;
332 wdata->verf.committed = oir->committed;
333 } else {
334 wdata->header->pnfs_error = status;
336 objlayout_iodone(oir);
337 /* must not use oir after this point */
339 dprintk("%s: Return status %zd committed %d sync=%d\n", __func__,
340 status, wdata->verf.committed, sync);
342 if (sync)
343 pnfs_ld_write_done(wdata);
344 else {
345 INIT_WORK(&wdata->task.u.tk_work, _rpc_write_complete);
346 schedule_work(&wdata->task.u.tk_work);
351 * Perform sync or async writes.
353 enum pnfs_try_status
354 objlayout_write_pagelist(struct nfs_write_data *wdata,
355 int how)
357 struct nfs_pgio_header *hdr = wdata->header;
358 int err;
360 _fix_verify_io_params(hdr->lseg, &wdata->args.pages,
361 &wdata->args.pgbase,
362 wdata->args.offset, wdata->args.count);
364 err = objio_write_pagelist(wdata, how);
365 if (unlikely(err)) {
366 hdr->pnfs_error = err;
367 dprintk("%s: Returned Error %d\n", __func__, err);
368 return PNFS_NOT_ATTEMPTED;
370 return PNFS_ATTEMPTED;
373 void
374 objlayout_encode_layoutcommit(struct pnfs_layout_hdr *pnfslay,
375 struct xdr_stream *xdr,
376 const struct nfs4_layoutcommit_args *args)
378 struct objlayout *objlay = OBJLAYOUT(pnfslay);
379 struct pnfs_osd_layoutupdate lou;
380 __be32 *start;
382 dprintk("%s: Begin\n", __func__);
384 spin_lock(&objlay->lock);
385 lou.dsu_valid = (objlay->delta_space_valid == OBJ_DSU_VALID);
386 lou.dsu_delta = objlay->delta_space_used;
387 objlay->delta_space_used = 0;
388 objlay->delta_space_valid = OBJ_DSU_INIT;
389 lou.olu_ioerr_flag = !list_empty(&objlay->err_list);
390 spin_unlock(&objlay->lock);
392 start = xdr_reserve_space(xdr, 4);
394 BUG_ON(pnfs_osd_xdr_encode_layoutupdate(xdr, &lou));
396 *start = cpu_to_be32((xdr->p - start - 1) * 4);
398 dprintk("%s: Return delta_space_used %lld err %d\n", __func__,
399 lou.dsu_delta, lou.olu_ioerr_flag);
402 static int
403 err_prio(u32 oer_errno)
405 switch (oer_errno) {
406 case 0:
407 return 0;
409 case PNFS_OSD_ERR_RESOURCE:
410 return OSD_ERR_PRI_RESOURCE;
411 case PNFS_OSD_ERR_BAD_CRED:
412 return OSD_ERR_PRI_BAD_CRED;
413 case PNFS_OSD_ERR_NO_ACCESS:
414 return OSD_ERR_PRI_NO_ACCESS;
415 case PNFS_OSD_ERR_UNREACHABLE:
416 return OSD_ERR_PRI_UNREACHABLE;
417 case PNFS_OSD_ERR_NOT_FOUND:
418 return OSD_ERR_PRI_NOT_FOUND;
419 case PNFS_OSD_ERR_NO_SPACE:
420 return OSD_ERR_PRI_NO_SPACE;
421 default:
422 WARN_ON(1);
423 /* fallthrough */
424 case PNFS_OSD_ERR_EIO:
425 return OSD_ERR_PRI_EIO;
429 static void
430 merge_ioerr(struct pnfs_osd_ioerr *dest_err,
431 const struct pnfs_osd_ioerr *src_err)
433 u64 dest_end, src_end;
435 if (!dest_err->oer_errno) {
436 *dest_err = *src_err;
437 /* accumulated device must be blank */
438 memset(&dest_err->oer_component.oid_device_id, 0,
439 sizeof(dest_err->oer_component.oid_device_id));
441 return;
444 if (dest_err->oer_component.oid_partition_id !=
445 src_err->oer_component.oid_partition_id)
446 dest_err->oer_component.oid_partition_id = 0;
448 if (dest_err->oer_component.oid_object_id !=
449 src_err->oer_component.oid_object_id)
450 dest_err->oer_component.oid_object_id = 0;
452 if (dest_err->oer_comp_offset > src_err->oer_comp_offset)
453 dest_err->oer_comp_offset = src_err->oer_comp_offset;
455 dest_end = end_offset(dest_err->oer_comp_offset,
456 dest_err->oer_comp_length);
457 src_end = end_offset(src_err->oer_comp_offset,
458 src_err->oer_comp_length);
459 if (dest_end < src_end)
460 dest_end = src_end;
462 dest_err->oer_comp_length = dest_end - dest_err->oer_comp_offset;
464 if ((src_err->oer_iswrite == dest_err->oer_iswrite) &&
465 (err_prio(src_err->oer_errno) > err_prio(dest_err->oer_errno))) {
466 dest_err->oer_errno = src_err->oer_errno;
467 } else if (src_err->oer_iswrite) {
468 dest_err->oer_iswrite = true;
469 dest_err->oer_errno = src_err->oer_errno;
473 static void
474 encode_accumulated_error(struct objlayout *objlay, __be32 *p)
476 struct objlayout_io_res *oir, *tmp;
477 struct pnfs_osd_ioerr accumulated_err = {.oer_errno = 0};
479 list_for_each_entry_safe(oir, tmp, &objlay->err_list, err_list) {
480 unsigned i;
482 for (i = 0; i < oir->num_comps; i++) {
483 struct pnfs_osd_ioerr *ioerr = &oir->ioerrs[i];
485 if (!ioerr->oer_errno)
486 continue;
488 printk(KERN_ERR "NFS: %s: err[%d]: errno=%d "
489 "is_write=%d dev(%llx:%llx) par=0x%llx "
490 "obj=0x%llx offset=0x%llx length=0x%llx\n",
491 __func__, i, ioerr->oer_errno,
492 ioerr->oer_iswrite,
493 _DEVID_LO(&ioerr->oer_component.oid_device_id),
494 _DEVID_HI(&ioerr->oer_component.oid_device_id),
495 ioerr->oer_component.oid_partition_id,
496 ioerr->oer_component.oid_object_id,
497 ioerr->oer_comp_offset,
498 ioerr->oer_comp_length);
500 merge_ioerr(&accumulated_err, ioerr);
502 list_del(&oir->err_list);
503 objio_free_result(oir);
506 pnfs_osd_xdr_encode_ioerr(p, &accumulated_err);
509 void
510 objlayout_encode_layoutreturn(struct pnfs_layout_hdr *pnfslay,
511 struct xdr_stream *xdr,
512 const struct nfs4_layoutreturn_args *args)
514 struct objlayout *objlay = OBJLAYOUT(pnfslay);
515 struct objlayout_io_res *oir, *tmp;
516 __be32 *start;
518 dprintk("%s: Begin\n", __func__);
519 start = xdr_reserve_space(xdr, 4);
520 BUG_ON(!start);
522 spin_lock(&objlay->lock);
524 list_for_each_entry_safe(oir, tmp, &objlay->err_list, err_list) {
525 __be32 *last_xdr = NULL, *p;
526 unsigned i;
527 int res = 0;
529 for (i = 0; i < oir->num_comps; i++) {
530 struct pnfs_osd_ioerr *ioerr = &oir->ioerrs[i];
532 if (!ioerr->oer_errno)
533 continue;
535 dprintk("%s: err[%d]: errno=%d is_write=%d "
536 "dev(%llx:%llx) par=0x%llx obj=0x%llx "
537 "offset=0x%llx length=0x%llx\n",
538 __func__, i, ioerr->oer_errno,
539 ioerr->oer_iswrite,
540 _DEVID_LO(&ioerr->oer_component.oid_device_id),
541 _DEVID_HI(&ioerr->oer_component.oid_device_id),
542 ioerr->oer_component.oid_partition_id,
543 ioerr->oer_component.oid_object_id,
544 ioerr->oer_comp_offset,
545 ioerr->oer_comp_length);
547 p = pnfs_osd_xdr_ioerr_reserve_space(xdr);
548 if (unlikely(!p)) {
549 res = -E2BIG;
550 break; /* accumulated_error */
553 last_xdr = p;
554 pnfs_osd_xdr_encode_ioerr(p, &oir->ioerrs[i]);
557 /* TODO: use xdr_write_pages */
558 if (unlikely(res)) {
559 /* no space for even one error descriptor */
560 BUG_ON(!last_xdr);
562 /* we've encountered a situation with lots and lots of
563 * errors and no space to encode them all. Use the last
564 * available slot to report the union of all the
565 * remaining errors.
567 encode_accumulated_error(objlay, last_xdr);
568 goto loop_done;
570 list_del(&oir->err_list);
571 objio_free_result(oir);
573 loop_done:
574 spin_unlock(&objlay->lock);
576 *start = cpu_to_be32((xdr->p - start - 1) * 4);
577 dprintk("%s: Return\n", __func__);
582 * Get Device Info API for io engines
584 struct objlayout_deviceinfo {
585 struct page *page;
586 struct pnfs_osd_deviceaddr da; /* This must be last */
589 /* Initialize and call nfs_getdeviceinfo, then decode and return a
590 * "struct pnfs_osd_deviceaddr *" Eventually objlayout_put_deviceinfo()
591 * should be called.
593 int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
594 struct nfs4_deviceid *d_id, struct pnfs_osd_deviceaddr **deviceaddr,
595 gfp_t gfp_flags)
597 struct objlayout_deviceinfo *odi;
598 struct pnfs_device pd;
599 struct page *page, **pages;
600 u32 *p;
601 int err;
603 page = alloc_page(gfp_flags);
604 if (!page)
605 return -ENOMEM;
607 pages = &page;
608 pd.pages = pages;
610 memcpy(&pd.dev_id, d_id, sizeof(*d_id));
611 pd.layout_type = LAYOUT_OSD2_OBJECTS;
612 pd.pages = &page;
613 pd.pgbase = 0;
614 pd.pglen = PAGE_SIZE;
615 pd.mincount = 0;
617 err = nfs4_proc_getdeviceinfo(NFS_SERVER(pnfslay->plh_inode), &pd);
618 dprintk("%s nfs_getdeviceinfo returned %d\n", __func__, err);
619 if (err)
620 goto err_out;
622 p = page_address(page);
623 odi = kzalloc(sizeof(*odi), gfp_flags);
624 if (!odi) {
625 err = -ENOMEM;
626 goto err_out;
628 pnfs_osd_xdr_decode_deviceaddr(&odi->da, p);
629 odi->page = page;
630 *deviceaddr = &odi->da;
631 return 0;
633 err_out:
634 __free_page(page);
635 return err;
638 void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
640 struct objlayout_deviceinfo *odi = container_of(deviceaddr,
641 struct objlayout_deviceinfo,
642 da);
644 __free_page(odi->page);
645 kfree(odi);
648 enum {
649 OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64,
650 OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1,
651 OSD_LOGIN_UPCALL_PATHLEN = 256
654 static char osd_login_prog[OSD_LOGIN_UPCALL_PATHLEN] = "/sbin/osd_login";
656 module_param_string(osd_login_prog, osd_login_prog, sizeof(osd_login_prog),
657 0600);
658 MODULE_PARM_DESC(osd_login_prog, "Path to the osd_login upcall program");
660 struct __auto_login {
661 char uri[OBJLAYOUT_MAX_URI_LEN];
662 char osdname[OBJLAYOUT_MAX_OSDNAME_LEN];
663 char systemid_hex[OBJLAYOUT_MAX_SYSID_HEX_LEN];
666 static int __objlayout_upcall(struct __auto_login *login)
668 static char *envp[] = { "HOME=/",
669 "TERM=linux",
670 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
671 NULL
673 char *argv[8];
674 int ret;
676 if (unlikely(!osd_login_prog[0])) {
677 dprintk("%s: osd_login_prog is disabled\n", __func__);
678 return -EACCES;
681 dprintk("%s uri: %s\n", __func__, login->uri);
682 dprintk("%s osdname %s\n", __func__, login->osdname);
683 dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex);
685 argv[0] = (char *)osd_login_prog;
686 argv[1] = "-u";
687 argv[2] = login->uri;
688 argv[3] = "-o";
689 argv[4] = login->osdname;
690 argv[5] = "-s";
691 argv[6] = login->systemid_hex;
692 argv[7] = NULL;
694 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
696 * Disable the upcall mechanism if we're getting an ENOENT or
697 * EACCES error. The admin can re-enable it on the fly by using
698 * sysfs to set the objlayoutdriver.osd_login_prog module parameter once
699 * the problem has been fixed.
701 if (ret == -ENOENT || ret == -EACCES) {
702 printk(KERN_ERR "PNFS-OBJ: %s was not found please set "
703 "objlayoutdriver.osd_login_prog kernel parameter!\n",
704 osd_login_prog);
705 osd_login_prog[0] = '\0';
707 dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret);
709 return ret;
712 /* Assume dest is all zeros */
713 static void __copy_nfsS_and_zero_terminate(struct nfs4_string s,
714 char *dest, int max_len,
715 const char *var_name)
717 if (!s.len)
718 return;
720 if (s.len >= max_len) {
721 pr_warn_ratelimited(
722 "objlayout_autologin: %s: s.len(%d) >= max_len(%d)",
723 var_name, s.len, max_len);
724 s.len = max_len - 1; /* space for null terminator */
727 memcpy(dest, s.data, s.len);
730 /* Assume sysid is all zeros */
731 static void _sysid_2_hex(struct nfs4_string s,
732 char sysid[OBJLAYOUT_MAX_SYSID_HEX_LEN])
734 int i;
735 char *cur;
737 if (!s.len)
738 return;
740 if (s.len != OSD_SYSTEMID_LEN) {
741 pr_warn_ratelimited(
742 "objlayout_autologin: systemid_len(%d) != OSD_SYSTEMID_LEN",
743 s.len);
744 if (s.len > OSD_SYSTEMID_LEN)
745 s.len = OSD_SYSTEMID_LEN;
748 cur = sysid;
749 for (i = 0; i < s.len; i++)
750 cur = hex_byte_pack(cur, s.data[i]);
753 int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr)
755 int rc;
756 struct __auto_login login;
758 if (!deviceaddr->oda_targetaddr.ota_netaddr.r_addr.len)
759 return -ENODEV;
761 memset(&login, 0, sizeof(login));
762 __copy_nfsS_and_zero_terminate(
763 deviceaddr->oda_targetaddr.ota_netaddr.r_addr,
764 login.uri, sizeof(login.uri), "URI");
766 __copy_nfsS_and_zero_terminate(
767 deviceaddr->oda_osdname,
768 login.osdname, sizeof(login.osdname), "OSDNAME");
770 _sysid_2_hex(deviceaddr->oda_systemid, login.systemid_hex);
772 rc = __objlayout_upcall(&login);
773 if (rc > 0) /* script returns positive values */
774 rc = -ENODEV;
776 return rc;