/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
+ * Copyright (C) 2001-2003 Cluster File Systems, Inc.
*
* This file is part of Lustre, http://www.sf.net/projects/lustre/
*
* You should have received a copy of the GNU General Public License
* along with Lustre; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
*/
#define EXPORT_SYMTAB
#include <linux/obd_class.h>
#include <linux/lustre_mds.h>
-static int mdc_reint(struct ptlrpc_client *cl, struct ptlrpc_request *request)
+/* mdc_setattr does its own semaphore handling */
+static int mdc_reint(struct ptlrpc_request *request, int level)
{
int rc;
+ __u32 *opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0);
+
+ request->rq_level = level;
- rc = ptlrpc_queue_wait(cl, request);
- rc = ptlrpc_check_status(request, rc);
- if (rc)
- CERROR("error in handling %d\n", rc);
+ if (!(*opcodeptr == REINT_SETATTR))
+ mdc_get_rpc_lock(&mdc_rpc_lock, NULL);
+ rc = ptlrpc_queue_wait(request);
+ if (!(*opcodeptr == REINT_SETATTR))
+ mdc_put_rpc_lock(&mdc_rpc_lock, NULL);
+ if (rc) {
+ CDEBUG(D_INFO, "error in handling %d\n", rc);
+ } else {
+ /* For future resend/replays. */
+ *opcodeptr |= REINT_REPLAYING;
+ }
return rc;
}
-int mdc_setattr(struct ptlrpc_client *cl, struct lustre_peer *peer,
- struct inode *inode, struct iattr *iattr,
+/* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
+ * should take the normal semaphore and go to the normal portal.
+ *
+ * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
+ * magic open-path setattr that should take the setattr semaphore and
+ * go to the setattr portal. */
+int mdc_setattr(struct lustre_handle *conn, struct inode *inode,
+ struct iattr *iattr, void *ea, int ealen,
struct ptlrpc_request **request)
{
- struct mds_rec_setattr *rec;
struct ptlrpc_request *req;
- int rc, size = sizeof(*rec);
+ struct mds_rec_setattr *rec;
+ struct mdc_rpc_lock *rpc_lock;
+ int rc, bufcount = 1, size[2] = {sizeof(*rec), ealen};
ENTRY;
- req = ptlrpc_prep_req(cl, peer, MDS_REINT, 1, &size, NULL);
+ LASSERT(iattr != NULL);
+
+ if (ealen > 0)
+ bufcount = 2;
+
+ req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
+ size, NULL);
if (!req)
RETURN(-ENOMEM);
- rec = lustre_msg_buf(req->rq_reqmsg, 0);
- mds_setattr_pack(rec, inode, iattr);
+ if (iattr->ia_valid & ATTR_FROM_OPEN) {
+ req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
+ rpc_lock = &mdc_setattr_lock;
+ } else
+ rpc_lock = &mdc_rpc_lock;
- size = sizeof(struct mds_body);
- req->rq_replen = lustre_msg_size(1, &size);
+ mds_setattr_pack(req, inode, iattr, ea, ealen);
+
+ size[0] = sizeof(struct mds_body);
+ req->rq_replen = lustre_msg_size(1, size);
+
+ mdc_get_rpc_lock(rpc_lock, NULL);
+ rc = mdc_reint(req, LUSTRE_CONN_FULL);
+ mdc_put_rpc_lock(rpc_lock, NULL);
- rc = mdc_reint(cl, req);
*request = req;
+ if (rc == -ERESTARTSYS)
+ rc = 0;
RETURN(rc);
}
-int mdc_create(struct ptlrpc_client *cl, struct lustre_peer *peer,
- struct inode *dir, const char *name, int namelen,
- const char *tgt, int tgtlen, int mode, __u64 id, __u32 uid,
- __u32 gid, __u64 time, struct ptlrpc_request **request)
+int mdc_create(struct lustre_handle *conn, struct inode *dir,
+ const char *name, int namelen, const void *data, int datalen,
+ int mode, __u32 uid, __u32 gid, __u64 time, __u64 rdev,
+ struct ptlrpc_request **request)
{
- struct mds_rec_create *rec;
struct ptlrpc_request *req;
- int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
- char *tmp;
+ int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
+ int level, bufcount = 2;
ENTRY;
- req = ptlrpc_prep_req(cl, peer, MDS_REINT, 3, size, NULL);
+ if (data && datalen) {
+ size[bufcount] = datalen;
+ bufcount++;
+ }
+
+ req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
+ size, NULL);
if (!req)
RETURN(-ENOMEM);
- rec = lustre_msg_buf(req->rq_reqmsg, 0);
- mds_create_pack(rec, dir, mode, id, uid, gid, time);
+ /* mds_create_pack fills msg->bufs[1] with name
+ * and msg->bufs[2] with tgt, for symlinks or lov MD data */
+ mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
+ name, namelen, data, datalen);
- tmp = lustre_msg_buf(req->rq_reqmsg, 1);
- LOGL0(name, namelen, tmp);
+ size[0] = sizeof(struct mds_body);
+ req->rq_replen = lustre_msg_size(1, size);
- if (tgt) {
- tmp = lustre_msg_buf(req->rq_reqmsg, 2);
- LOGL0(tgt, tgtlen, tmp);
+ level = LUSTRE_CONN_FULL;
+ resend:
+ rc = mdc_reint(req, level);
+ /* Resend if we were told to. */
+ if (rc == -ERESTARTSYS) {
+ level = LUSTRE_CONN_RECOVD;
+ req->rq_flags = 0;
+ goto resend;
}
- size[0] = sizeof(struct mds_body);
- req->rq_replen = lustre_msg_size(1, size);
+ if (!rc)
+ mdc_store_inode_generation(req, 0, 0);
- rc = mdc_reint(cl, req);
*request = req;
-
RETURN(rc);
}
-int mdc_unlink(struct ptlrpc_client *cl, struct lustre_peer *peer,
- struct inode *dir, struct inode *child, const char *name,
- int namelen, struct ptlrpc_request **request)
+int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
+ struct inode *child, __u32 mode, const char *name, int namelen,
+ struct ptlrpc_request **request)
{
- struct mds_rec_unlink *rec;
- struct ptlrpc_request *req;
- int rc, size[2] = {sizeof(*rec), namelen + 1};
- char *tmp;
+ struct obd_device *obddev = class_conn2obd(conn);
+ struct ptlrpc_request *req = *request;
+ int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
ENTRY;
- req = ptlrpc_prep_req(cl, peer, MDS_REINT, 2, size, NULL);
+ LASSERT(req == NULL);
+
+ req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
+ NULL);
if (!req)
RETURN(-ENOMEM);
-
- rec = lustre_msg_buf(req->rq_reqmsg, 0);
- mds_unlink_pack(rec, dir, child);
-
- tmp = lustre_msg_buf(req->rq_reqmsg, 1);
- LOGL0(name, namelen, tmp);
+ *request = req;
size[0] = sizeof(struct mds_body);
- req->rq_replen = lustre_msg_size(1, size);
+ size[1] = obddev->u.cli.cl_max_mds_easize;
+ req->rq_replen = lustre_msg_size(2, size);
- rc = mdc_reint(cl, req);
- *request = req;
+ mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
+ rc = mdc_reint(req, LUSTRE_CONN_FULL);
+ if (rc == -ERESTARTSYS)
+ rc = 0;
RETURN(rc);
}
-int mdc_link(struct ptlrpc_client *cl, struct lustre_peer *peer,
- struct dentry *src, struct inode *dir, const char *name,
+int mdc_link(struct lustre_handle *conn,
+ struct inode *src, struct inode *dir, const char *name,
int namelen, struct ptlrpc_request **request)
{
- struct mds_rec_link *rec;
struct ptlrpc_request *req;
- int rc, size[2] = {sizeof(*rec), namelen + 1};
- char *tmp;
+ int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
ENTRY;
- req = ptlrpc_prep_req(cl, peer, MDS_REINT, 2, size, NULL);
+ req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
+ NULL);
if (!req)
RETURN(-ENOMEM);
- rec = lustre_msg_buf(req->rq_reqmsg, 0);
- mds_link_pack(rec, src->d_inode, dir);
-
- tmp = lustre_msg_buf(req->rq_reqmsg, 1);
- LOGL0(name, namelen, tmp);
+ mds_link_pack(req, 0, src, dir, name, namelen);
size[0] = sizeof(struct mds_body);
req->rq_replen = lustre_msg_size(1, size);
- rc = mdc_reint(cl, req);
+ rc = mdc_reint(req, LUSTRE_CONN_FULL);
*request = req;
+ if (rc == -ERESTARTSYS)
+ rc = 0;
RETURN(rc);
}
-int mdc_rename(struct ptlrpc_client *cl, struct lustre_peer *peer,
+int mdc_rename(struct lustre_handle *conn,
struct inode *src, struct inode *tgt, const char *old,
int oldlen, const char *new, int newlen,
struct ptlrpc_request **request)
{
- struct mds_rec_rename *rec;
struct ptlrpc_request *req;
- int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
- char *tmp;
+ int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
+ newlen + 1};
ENTRY;
- req = ptlrpc_prep_req(cl, peer, MDS_REINT, 3, size, NULL);
+ req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size,
+ NULL);
if (!req)
RETURN(-ENOMEM);
- rec = lustre_msg_buf(req->rq_reqmsg, 0);
- mds_rename_pack(rec, src, tgt);
-
- tmp = lustre_msg_buf(req->rq_reqmsg, 1);
- LOGL0(old, oldlen, tmp);
-
- if (tgt) {
- tmp = lustre_msg_buf(req->rq_reqmsg, 2);
- LOGL0(new, newlen, tmp);
- }
+ mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
size[0] = sizeof(struct mds_body);
req->rq_replen = lustre_msg_size(1, size);
- rc = mdc_reint(cl, req);
+ rc = mdc_reint(req, LUSTRE_CONN_FULL);
*request = req;
+ if (rc == -ERESTARTSYS)
+ rc = 0;
RETURN(rc);
}