-static int mdc_ioctl(long cmd, struct lustre_handle *conn, int len, void *karg,
- void *uarg)
-{
-#if 0
- /* FIXME XXX : This should use the new ioc_data to pass args in */
- int err = 0;
- struct ptlrpc_client *cl;
- struct ptlrpc_connection *connection;
- struct lustre_handle *rconn;
- struct ptlrpc_request *request;
-
- ENTRY;
-
- if (_IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
- _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
- _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
- CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
- _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
- RETURN(-EINVAL);
- }
-
- ptlrpc_init_client(NULL, NULL,
- MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL, &cl);
-
- mdc_con2cl(conn, &cl, &connection, &rconn);
- switch (cmd) {
- case IOC_REQUEST_GETATTR: {
- CERROR("-- getting attr for ino %lu\n", arg);
- err = mdc_getattr(&cl, connection, (obd_id)arg, S_IFDIR, ~0, 0,
- &request);
- CERROR("-- done err %d\n", err);
-
- GOTO(out, err);
- }
-
- case IOC_REQUEST_READPAGE: {
- char *buf;
- OBD_ALLOC(buf, PAGE_SIZE);
- if (!buf) {
- err = -ENOMEM;
- GOTO(out, err);
- }
- CERROR("-- readpage 0 for ino %lu\n", arg);
- err = mdc_readpage(&cl, connection, arg, S_IFDIR, 0, buf,
- &request);
- CERROR("-- done err %d\n", err);
- OBD_FREE(buf, PAGE_SIZE);
-
- GOTO(out, err);
- }
-
- case IOC_REQUEST_SETATTR: {
- struct inode inode;
- struct iattr iattr;
-
- inode.i_ino = arg;
- inode.i_generation = 0;
- iattr.ia_mode = 040777;
- iattr.ia_atime = 0;
- iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
-
- err = mdc_setattr(&cl, connection, &inode, &iattr, &request);
- CERROR("-- done err %d\n", err);
-
- GOTO(out, err);
- }
-
- case IOC_REQUEST_CREATE: {
- struct inode inode;
- struct iattr iattr;
-
- inode.i_ino = arg;
- inode.i_generation = 0;
- iattr.ia_mode = 040777;
- iattr.ia_atime = 0;
- iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
-
- err = mdc_create(&cl, connection, &inode,
- "foofile", strlen("foofile"),
- NULL, 0, 0100707, 47114711,
- 11, 47, 0, NULL, &request);
- CERROR("-- done err %d\n", err);
-
- GOTO(out, err);
- }
-
- case IOC_REQUEST_OPEN: {
- __u64 fh, ino;
- copy_from_user(&ino, (__u64 *)arg, sizeof(ino));
- CERROR("-- opening ino %llu\n", (unsigned long long)ino);
- err = mdc_open(&cl, connection, ino, S_IFDIR, O_RDONLY, 4711,
- &fh, &request);
- copy_to_user((__u64 *)arg, &fh, sizeof(fh));
- CERROR("-- done err %d (fh=%Lu)\n", err,
- (unsigned long long)fh);
-
- GOTO(out, err);
- }
-
- case IOC_REQUEST_CLOSE: {
- CERROR("-- closing ino 2, filehandle %lu\n", arg);
- err = mdc_close(&cl, connection, 2, S_IFDIR, arg, &request);
- CERROR("-- done err %d\n", err);
-
- GOTO(out, err);
- }
-
- default:
- GOTO(out, err = -EINVAL);
- }
-
- out:
- ptlrpc_free_req(request);
- ptlrpc_put_connection(connection);
- ptlrpc_cleanup_client(&cl);
-
- RETURN(err);
-#endif
- return 0;
-}
-
-static int mdc_setup(struct obd_device *obddev, obd_count len, void *buf)
-{
- struct obd_ioctl_data* data = buf;
- struct mdc_obd *mdc = &obddev->u.mdc;
- char server_uuid[37];
- int rc;
- ENTRY;
-
- if (data->ioc_inllen1 < 1) {
- CERROR("osc setup requires a TARGET UUID\n");
- RETURN(-EINVAL);
- }
-
- if (data->ioc_inllen1 > 37) {
- CERROR("mdc UUID must be less than 38 characters\n");
- RETURN(-EINVAL);
- }
-
- if (data->ioc_inllen2 < 1) {
- CERROR("mdc setup requires a SERVER UUID\n");
- RETURN(-EINVAL);
- }
-
- if (data->ioc_inllen2 > 37) {
- CERROR("mdc UUID must be less than 38 characters\n");
- RETURN(-EINVAL);
- }
-
- memcpy(mdc->mdc_target_uuid, data->ioc_inlbuf1, data->ioc_inllen1);
- memcpy(server_uuid, data->ioc_inlbuf2, MIN(data->ioc_inllen2,
- sizeof(server_uuid)));
-
- mdc->mdc_conn = ptlrpc_uuid_to_connection(server_uuid);
- if (!mdc->mdc_conn)
- RETURN(-ENOENT);
-
- OBD_ALLOC(mdc->mdc_client, sizeof(*mdc->mdc_client));
- if (mdc->mdc_client == NULL)
- GOTO(out_conn, rc = -ENOMEM);
-
- OBD_ALLOC(mdc->mdc_ldlm_client, sizeof(*mdc->mdc_ldlm_client));
- if (mdc->mdc_ldlm_client == NULL)
- GOTO(out_client, rc = -ENOMEM);
-
- ptlrpc_init_client(NULL, NULL, MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
- mdc->mdc_client);
- ptlrpc_init_client(NULL, NULL, LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
- mdc->mdc_ldlm_client);
- mdc->mdc_client->cli_name = "mdc";
- mdc->mdc_ldlm_client->cli_name = "ldlm";
- mdc->mdc_max_mdsize = sizeof(struct lov_stripe_md);
- /* XXX get recovery hooked in here again */
- //ptlrpc_init_client(ptlrpc_connmgr, ll_recover,...
-
- ptlrpc_init_client(ptlrpc_connmgr, NULL,
- MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
- mdc->mdc_client);
-
- MOD_INC_USE_COUNT;
- RETURN(0);
-
- out_client:
- OBD_FREE(mdc->mdc_client, sizeof(*mdc->mdc_client));
- out_conn:
- ptlrpc_put_connection(mdc->mdc_conn);
- return rc;
-}
-
-static int mdc_cleanup(struct obd_device * obddev)
-{
- struct mdc_obd *mdc = &obddev->u.mdc;
-
- ptlrpc_cleanup_client(mdc->mdc_client);
- OBD_FREE(mdc->mdc_client, sizeof(*mdc->mdc_client));
- ptlrpc_cleanup_client(mdc->mdc_ldlm_client);
- OBD_FREE(mdc->mdc_ldlm_client, sizeof(*mdc->mdc_ldlm_client));
- ptlrpc_put_connection(mdc->mdc_conn);
-
- MOD_DEC_USE_COUNT;
- return 0;
-}
-
-static int mdc_connect(struct lustre_handle *conn, struct obd_device *obd)
-{
- struct mdc_obd *mdc = &obd->u.mdc;
- struct ptlrpc_request *request;
- int rc, size = sizeof(mdc->mdc_target_uuid);
- char *tmp = mdc->mdc_target_uuid;
-
- ENTRY;
-
- obd->obd_namespace =
- ldlm_namespace_new("mdc", LDLM_NAMESPACE_CLIENT);
- if (obd->obd_namespace == NULL)
- RETURN(-ENOMEM);
-
- MOD_INC_USE_COUNT;
- rc = class_connect(conn, obd);
- if (rc)
- RETURN(rc);
-
- request = ptlrpc_prep_req(mdc->mdc_client, mdc->mdc_conn,
- MDS_CONNECT, 1, &size, &tmp);
- if (!request)
- GOTO(out_disco, -ENOMEM);
-
- request->rq_level = LUSTRE_CONN_NEW;
- request->rq_replen = lustre_msg_size(0, NULL);
- /* Sending our local connection info breaks for local connections
- request->rq_reqmsg->addr = conn->addr;
- request->rq_reqmsg->cookie = conn->cookie;
- */
-
- rc = ptlrpc_queue_wait(request);
- rc = ptlrpc_check_status(request, rc);
- if (rc)
- GOTO(out, rc);
-
- class_rconn2export(conn, (struct lustre_handle *)request->rq_repmsg);
-
- EXIT;
- out:
- ptlrpc_free_req(request);
- out_disco:
- if (rc) {
- class_disconnect(conn);
- MOD_DEC_USE_COUNT;
- }
- return rc;
-}
-
-static int mdc_disconnect(struct lustre_handle *conn)
-{
- struct ptlrpc_client *cl;
- struct ptlrpc_connection *connection;
- struct lustre_handle *rconn;
- struct obd_device *obd = class_conn2obd(conn);
- struct ptlrpc_request *request;
- int rc;
- ENTRY;
-
- ldlm_namespace_free(obd->obd_namespace);
- mdc_con2cl(conn, &cl, &connection, &rconn);
- request = ptlrpc_prep_req2(cl, connection, rconn,
- MDS_DISCONNECT, 0, NULL, NULL);
- if (!request)
- RETURN(-ENOMEM);
-
- request->rq_replen = lustre_msg_size(0, NULL);
-
- rc = ptlrpc_queue_wait(request);
- if (rc)
- GOTO(out, rc);
- rc = class_disconnect(conn);
- if (!rc)
- MOD_DEC_USE_COUNT;
- out:
- ptlrpc_free_req(request);
- return rc;
-}
-